2

What is the difference between reference and pointer?

Shathana. S.R. Answered question July 6, 2023
User Avatar

Reference

Pointer

The value of a reference cannot be reassigned The value of a pointer can be reassigned
It can never hold a null value as it needs an existing value to become an alias of It can hold or point at a null value and be termed as a nullptr or null pointer
It cannot work with arrays It can work with arrays
To access the members of class/struct it uses a ‘ . ‘ To access the members of class/struct it uses a ‘ -> ‘
The memory location of reference can be accessed easily or it can be used directly The memory location of a pointer cannot be accessed easily as we have to use a dereference ‘ * ‘