by ThoAppelsin · 8y ago · 0 comments
I was wondering if `int &a2 = a;` allocates memory in stack to make `a2` refer to `&a`, or does `a2` somehow truly become an alias for `a` in symbol table. As you've said that the assembly would look the same as pointers being dereferenced, then I suppose C++'s reference types are just a syntax sugar around the C's way of achieving the pass-by-reference concept through passing the address and then dereferencing it.
However, outside of function signatures, if you write:
int a = 2; int &aref = a; int b = aref;
I'd assume that the compiler is smart enough to optimize away &aref.