References - Are they even a variable?

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:
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?)

Sorry if I explain that really confusingly.
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.
If the C++ standard doesn't say anything about it, then I suppose it's up to the compiler. Best answer you could give!

Thanks a lot!
Topic archived. No new replies allowed.