0Pricing
C++ Academy · Lesson

When to Use Pointers vs References

Pick between pointers and references based on optionality and ownership semantics.

Different Tools for Different Jobs

References and pointers both let you indirect to another object — but with different semantics. Use each where it shines.

References for Mandatory Targets

A reference cannot be null and cannot be reseated. Use a reference parameter when the function always needs a real object.

void render(const Image& img);   // must have an image

All lessons in this course

  1. Raw Pointers and the Address-of Operator
  2. Dereferencing and Pointer Arithmetic
  3. nullptr and Null Pointer Safety
  4. When to Use Pointers vs References
← Back to C++ Academy