What is the difference between a pointer and a reference in C++?
A pointer is a variable that holds a memory address and can be null, reassigned to point elsewhere, and used with pointer arithmetic. A reference is an alias for an existing variable, must be initialised when declared, cannot be null, and cannot be changed to refer to something else. Use references for simple aliasing and pointers when you need to reassign or represent nothing.
Pointer
A pointer stores an address. You can make it point somewhere else, set it to nullptr, and follow it with the dereference operator to reach the value.
int x = 10;
int* p = &x; // p holds the address of x
*p = 20; // x is now 20
p = nullptr; // allowed
Reference
A reference is another name for an existing variable. Once bound it always refers to that same variable, so it is safer and cleaner for simple cases.
int x = 10;
int& r = x; // r is an alias for x
r = 20; // x is now 20
A crisp summary is a pointer can be null and reassigned, a reference must bind once and cannot be null. Saying you prefer references unless you need reassignment or optional absence shows good modern C++ instincts.
Common follow up questions
Related interview questions
Want the full C++ guide?
Read every C++ concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the C++ guide All C++ questions