differnce between pointer and reference
A pointer can be initialized to any value anytime after it is declared.
A reference must be initialized when it is declared.
A pointer can be assigned to point to a NULL value.
A pointer can be re-assigned. This property is useful for implementation of data structures like linked list, tree, etc.
On the other hand, a reference cannot be re-assigned, and must be assigned at initialization.
Memory Address:
A pointer has its own memory address and size on the stack whereas
A reference shares the same memory address (with the original variable) but also takes up some space on the stack.
Comments
Post a Comment