Skip to main content
Object reference vs pointer
Differences
- You think of pointer as just another type like int, char, float, it takes up a constant amount of spaces in memory, and you can assign values to them.
- The value you assign to them is a memory address, you can point them to a memory address. The type of the pointer tell it how to interpret the memory address that it is assigned.
- You can interpret the memory address pointed by the pointer using the dereferencing operator (*).
- An object reference on the other hand, first of all, doesn't exist in C, but in C++.
- An object reference is implemented via pointer, but a constant pointer with automatic indirection, the compiler will apply the dereferencing for you automatically.
- An object reference cannot be null, while a pointer can be pointed to
NULL
.
- Think of object references as an alias to the existing object in memory. Another variable name if you will.