Given:
int i = 42;
int j = 43;
int k = 44;
By looking at the variables addresses we know that each one takes up 4 bytes (on most platforms).
However, considering:
int i = 42;
int& j = i;
int k = 44;
We will see that variable i
indeed takes 4 bytes, but j
takes none and k
takes again 4 bytes on the stack.
What is happening here? It looks like j
is simply non-existent in runtime. And what about a reference I receive as a function argument? That must take some space on the stack...
And while we're at it - why can't I define an array or references?
int&[] arr = new int&[SIZE]; // compiler error! array of references is illegal
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…