C++20 sections · 1024 units
Open in Course

References vs Pointers

Key differences

References can't be null and can't be rebound. Pointers can be nullptr and point to different things. References are safer but less flexible. References use cleaner syntax: ref = 10 not *ptr = 10.

Pointers require explicit dereferencing, making indirection visible but adding clutter. I use references for function parameters that modify arguments, pointers when I need optionality or reassignment.