← C++ Programming learning path
C++ Programming · Module 5 of 10

Pointers and memory

Understand addresses, pointers and dynamic memory.

📖 Key ideas

  1. A pointer stores a memory address: int* p = &x;
  2. *p dereferences to access the value.
  3. new allocates on the heap; delete frees it.
  4. Memory leaks happen when memory is never freed.
  5. Prefer smart pointers: std::unique_ptr, std::shared_ptr.
💡 Real-life example: A pointer is a house address written on paper; dereferencing is visiting that house.
PointerVariable holding an address
&Address-of operator
HeapDynamic memory region
Smart pointerAutomatically frees memory