0
I want to discuss this problem can someone understand me this problem?
What is the output of this code? int x = 50; int &y = x; ++x; cout << ++x + y;
2 ответов
+ 3
x = 50 initial state
y stores the address of x
++x; changes x to 51
and cout << ++x + y; here ++x will increment x again and making it 52 then y will call the x from the address. Which has 52 there as well
So 52 + 52 = 104
0
int &y = x;
Here we create an int reference, and we initialize it by setting the reference to point to variable <x>. From this moment on, <y> behaves like an alias for <y>, whatever happens to <x> also happens to <y>.
https://www.differencebetween.com/difference-between-pointer-and-vs-reference/