Reference variable

Aug 18, 2015 at 1:23pm
There is a small point that I don't really understand about reference variable. For example, if we declare b as a reference to a, how many bytes does the program below cost? 8 bytes for two ints or 4 bytes?
1
2
int a=3;
int &b=a;
Last edited on Aug 18, 2015 at 1:24pm
Aug 18, 2015 at 1:30pm
Answer: you should not care. C++ provides references as abstraction and compilers can implement them in any way they want. Obviously all proper compilers aim to lessen cost of them.

Technicalities: in this case b is simply an alias for a and any compiler worth using will not allocate any space for it. In fact you would not be able to tell if that reference existed at all when studying resulting assembly.
Topic archived. No new replies allowed.