Google News
logo
CPP - Interview Questions
What is the difference between reference and pointer?
Following are the differences between reference and pointer :

Reference
Pointer
Reference behaves like an alias for an existing variable, i.e., it is a temporary variable. The pointer is a variable which stores the address of a variable.
Reference variable does not require any indirection operator to access the value. A reference variable can be used directly to access the value. Pointer variable requires an indirection operator to access the value of a variable.
Once the reference variable is assigned, then it cannot be reassigned with different address values. The pointer variable is an independent variable means that it can be reassigned to point to different objects.
A null value cannot be assigned to the reference variable. A null value can be assigned to the reference variable.
It is necessary to initialize the variable at the time of declaration. It is not necessary to initialize the variable at the time of declaration.
Advertisement