← C++ Programming learning pathC++ Programming · Module 5 of 10
Pointers and memory
Understand addresses, pointers and dynamic memory.
📖 Key ideas
- A pointer stores a memory address: int* p = &x;
- *p dereferences to access the value.
- new allocates on the heap; delete frees it.
- Memory leaks happen when memory is never freed.
- 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