What would be a brief definition of a reference variable in C++?
Reference variables (let a
), just say for easy understanding, another name of variable (let x
), which holds the same exact memory location as that of x
.
int &a = x;
refers that a holds same memory location as that of x
.
For example, say two roommates share the same room. One friends name is x
and another friends name is a
. If a
changes the location of the table placed in the room, from position (x,y,z)
to (x1,y1,z1)
then changes are visible to friend x
as well and vice versa.