I'm currently reading a book on C++, and I like to understand how things work fully or else they just don't make sense to me.
Say I do:
1 2
int a = 5;
int &i = a;
Does i really take up extra memory, or is it simply an alias for a?
Basically, are references pointers or simply another name for a variable (to the computer)? (Though I can respect that a reference function would take up extra memory. But, to the machine, what it returns is basically just as if you typed in the returned variable?)
It is unspecified by the C++ standard whether references take up storage. However in practice they are implemented using pointers, so they generally take up the same space as a pointer.
However, in a simple case like this any optimizing compiler will optimize the reference away, as it already knows that it is an alias for a.