I have not deeply understood the reference type in c++. So I wrote a tiny piece of code:
int a = 10;
int& b = a;
cout << "a: " << a << endl;
cout << "b: " << b << endl;
cout << "&a: " << &a << endl;
cout << "&b: " << &b << endl;
the output is:
a: 10
b: 10
&a: 0x7ffebd76ac6c
&b: 0x7ffebd76ac6c
And I noticed, without surprise, that a's and b's addresses are the same. Then I disassembled to find out how actually the reference is considered for the compiler. Here the code:
40096e: c7 45 dc 0a 00 00 00 mov DWORD PTR [rbp-0x24],0xa
400975: 48 8d 45 dc lea rax,[rbp-0x24]
400979: 48 89 45 e0 mov QWORD PTR [rbp-0x20],rax
If I'm correct, rbp-0x24 refers to the variable a, whereas rbp-0x20 refers to the variable b. But my doubt is: if after this three lines (and if I haven't done mistakes)
[rbp-0x20] = rbp-0x24
how could it be possible that both the variables' addresses are the same?