Notes

Thoughts, write-ups, and things worth remembering.

References vs pointers

#cpp#pointers Updated Sep 16, 2026

Both let you refer to another variable without copying it. A reference is the friendlier, more restricted cousin.

PointerReference
Can be nullyesno — must bind to something real at creation
Can be reassignedyesno — bound for life
Needs */-> to useyesno — looks like the object itself
Can do arithmeticyesno
int x = 5;
int& ref = x;   // ref IS x now, forever
int* ptr = &x;  // ptr points at x, but can later point elsewhere
ref = 10;       // x is now 10, no & or * needed

When to use which

Default to a reference — cleaner syntax, and “can’t be null” is one less thing to check. Reach for a pointer only when you genuinely need “might not point at anything” or “might point somewhere else later.”

Pointer basics