Week 10 - Intro to Pointers and Dynamic Data

Learning Objectives

Upon finishing this learning module, you should be able to:

  • Read code that uses pointers and references
  • Create dynamically allocated storage
No late work will be accepted after the last assignment's due date, to allow time for grading during finals week.
Quiz 4 is open this Thurs-Saturday. Covers weeks 8, 9, and 10 (make sure to practice with pointers before taking).

Schedule

Day 1

  • Photochop
  • Photochop mini assignment

Day 2

  • Pointer Basics
  • Read chapter 11.1-11.3
  • Pointer Worksheet

Day 3

  • Dynamic Memory
  • Read chapter 11.9

Day 4

  • Quiz 4
  • Final review

Activity Outline

PhotoChop

PhotoChop is a project that puts together a bunch of recent ideas - structs, typedefs, multidimensional arrays, and enums - and lets you have some fun manipulating images.

See the week 10 Files for the starter code. This video explains it:

PhotoChop mini-assignment (scored as extra credit in the CPPLab category - can add 5% to your CPPLab score). Make (at least) two new image functions - you should make one each from two different categories (Create New Image, Basic Image, Complex Image Modification, Moving Pixels, Combining Pixels, and Multiple Files).

Pointers

This week you do not have to write code using pointers (unless you do the challenge for assignment 9). Our goal with the material in Ch11 is just to gain an understanding of what pointers are and how they work. They are a tricky concept that we will learn more about in 162 and rely on heavily for 260... this is the gentle preview of the topic. So by all means, try things out in QtCreator, but keep in mind that our goal for now is just to understand them, not proficiently use them.

Read chapter 11.1-11.3 about the basics of pointers. This video helps explain what they are:

Do the Pointer worksheet from the Classroom files link. There is an example problem and key is available in that folder as well.

This C++ Code Visualizer can be a handy tool for visualizing what is happening in memory. It shows pointers as arrows to the location they point. That is a good high level mental model, but you should also understand that the pointer is storing something - a memory address.

Watch this video about dynamic memory:

Read 11.9

Final prep

The final exam will be a similar format to the midterm. There is a practice final available in elearn.