Module 5 · Lesson 2 of 212/26 in the course~18 min
Module lessons (2/2)
Pointers and Memory Stack/Heap
Lesson preview5 hands-on exercises readyCourse C++ · Module 5 — Data Structures and Pointers
Memory addresses (&), dereference (*), nullptr, dangling pointer and RAII.
What you'll learn in this lesson
- Extract the memory address with
&and read or mutate the cell pointed to with*ptr. - Always initialize and test null pointers using
nullptr. - Recognize in real time the difference between Stack frame and Heap, as well as deadly bugs like dangling pointer and memory leak in the interactive simulator.
Overview
Each variable lives at a specific address in RAM. While a reference (int&) is a fixed alias that can never be empty or reassigned, a pointer (int*) is a true variable that holds a memory address (or nullptr).
The unary operator & placed in front of a variable returns the exact address of its cell on the Stack:
Sections covered in this lesson
- 11. The Address Operator (
&) andint* ptr - 22. Dereferencing (
*ptr) - 33. Interactive Simulator: Stack, Heap, Leak & Dangling Pointer
- 44.
nullptrTyped and Security Rules - 5Practical exercises
- 6Check for understanding
Pro Lesson · Module 5 — Data Structures and Pointers
Unlock "Pointers and Memory Stack/Heap" and the full Course C++ curriculum
Memory addresses (&), dereference (*), nullptr, dangling pointer and RAII.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Course C++ plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.