Possible Duplicate:
How is reference implemented internally?
void f (int& a)
{
a ++;
}
int main ()
{
int b = 5;
f(b);
cout << b << endl; //prints 6
}
When I saw the syntax for references in C++, it initially looked like the variable b (if it were an object) would be copied into f. How do these references actually work under the hood? (Some simple asm would be great.)
In this case, the pass-by-reference most likely uses pointer semantics – i.e. the address of the object is probably passed as the parameter.\
Nope. That’s one of the upsides of references – no copying.
eaxwill contain the address ofb, and is then pushed onto the function argument stack.