It is not specified by the language as to how references are stored, but most compilers will implement them as pointers internally.
Regardless, since references are "transparent" to you as a programmer, when you write &b
you are in fact taking the address of the referand, not the reference. That's why you get the same address.
Similarly, writing &b=c
does nothing to the reference itself, but writes the value c
to pointer that is the address of a
(a meaningless thing). It is the same as int* ptr = &b; ptr = c;
It is important to understand that &
as "address of", and &
as in reference type notation, are two different things:
int a;
int* ptr = &a; // <--- taking (and storing) the address of `a`, i.e. a pointer
int& b = a; // <--- declares a reference to `a`; `b` now behaves like `a`
// Two entirely different meanings of `&`.
There is also a third meaning of &
, which is bitwise AND.
Anyway, if you want to re-seat a reference, you're out of luck. You simply cannot do that.