Lesson Two
Today is a really exciting day!
Really? Why?? I am so excited!!
Because today we'll learn how to allocate memory outside of a stack frame, so it can persist after a function returns!
Oh, boy! Oh, boy! This is gonna be great!
We will also learn more about pointers and see how important they are in C++ (and in other languages).
It turns out that pointers are really fundamental to lots of what you've done in CS so far, though you probably didn't know it!
This lesson will address the following goals in Group 4:
- Goal 4B (Pointers):
- Read, write, and visualize C++ code involving
- Pointers
- The indirection operator (
*
) - The index operator (
[ ]
) new
, anddelete
- Read, write, and visualize C++ code involving
- Goal 4C (Memory Management):
- Recognize memory management issues; specifically,
- Dangling pointers
- Double
deletes
- Memory leaks
- How to correct these issues
- Recognize memory management issues; specifically,
Outline
- Before You Start
- Elephant Parade Part 1: A Bad Idea
- The Heap and
new
- Null Pointers
- Elephant Parade Part 2:
new
andnullptr
- Mysterious Mysteries (Optional)
(This is a good spot for a break, if you feel like it!)
- Elephant Parade Part 3: Dynamically Allocated Arrays
- Elephant Parade Part 4: Memory Leak
- The
delete
Keyword - Elephant Parade Part 5: Dangling Pointer and Double Delete
- Key Points
- Before You Go…
To receive credit: complete all pages above, then this page will be complete as well (and get a green check emoji at the bottom right of the page).
(When logged in, completion status appears here.)