How does a C++ reference look,
memory-wise?
It doesn't. The C++ standard only says how it should behave, not how it should be implemented.
In the general case, compilers usually implement references as pointers. But they generally have more information about what a reference may point to, and use that for optimization.
Remember that the only requirement for a reference is that it behaves as an alias for the referenced object. So if the compiler encounters this code:
int i = 42;
int& j = i;
int k = 44;
what it sees is not "create a pointer to the variable i
" (although that is how the compiler may choose to implement it in some cases), but rather "make a note in the symbol table that j
is now an alias for i
."
The compiler doesn't have to create a new variable for j
, it simply has to remember that whenever j
is referenced from now on, it should really swap it out and use i
instead.
As for creating an array of references, you can't do it because it'd be useless and meaningless.
When you create an array, all elements are default-constructed. What does it mean to default-construct a reference? What does it point to? The entire point in references is that they re initialized to reference another object, after which they can not be reseated.
So if it could be done, you would end up with an array of references to nothing. And you'd be unable to change them to reference something because they'd been initialized already.