C++ - Pointers (Basics)
Overview
Estimated time: 40–60 minutes
Work with raw pointers: store addresses, dereference, and pass to functions for in-place modification.
Learning Objectives
- Create and dereference pointers safely.
- Use pointer parameters to modify caller data.
Examples
void inc(int* p){ if (p) ++*p; }
int main(){ int x=1; inc(&x); }
Common Pitfalls
- Dereferencing null or invalid pointers leads to undefined behavior.