Possible Duplicate:
Is there any way to find the address of a reference?
When we print the address of actual variable and reference variable it shows same address why?
Possible Duplicate:
Is there any way to find the address of a reference?
When we print the address of actual variable and reference variable it shows same address why?
A reference is an alias for another variable - it's just another name for thing that's assigned to the reference.
Behind the scenes the compiler might implement it using pointer mechanics, but if enough is known about the thing being aliased and the lifetime of the reference, the compiler can dispense with that
Because they're both pointing to the same memory location. That's basically what passing by reference is all about. Instead of passing (copying) the actual value of a variable, the address of it is sent for performance (and memory usage) reasons.
References act kind of like pointers, but they are more safer and differ from pointers in few ways. For more information have a look at this page.
It is also an important aside to know:
$8.3.2/3 - "It is unspecified whether or not a reference requires storage (3.7).".
Because it is a reference. Meaning it references the actual variable.
int i = ...;
int& ri = i;
In this example, ri
is like an alias for i
.