Saved Bookmarks
| 1. |
What are the differences between pointers and reference variables in C++? |
|
Answer» In C++, a pointer is a variable that keeps track of the memory address of another variable. A reference is an alias for a variable that ALREADY exists. A reference to a variable that has been initialised cannot be MODIFIED to refer to another variable. As a result, a reference is analogous to a const pointer. Pointer
A reference is supposed to be initialized at its time of declaration. int x = 6;int &ref = x;
A reference to a variable OBJECT cannot be modified once it has been initialised to a variable. |
|