+ 2
How did this result come out is 8181?
int x=80; int &y=x; ++x; cout<<x<<y;
11 Respostas
+ 4
If You Want Explanation Then Here I Am Telling You Step By Step
First You Initialised And Declared An Integer Type Variable With Value 80 Now After That You Initialised A Reference Variable y which is holding address of variable x
and when you performed pre increment on x this will increase the value of x by 1 so when you printed x this gave you 81 and when you printed y who’s pointing to x first go to memory location of x then printed the value of x which is 81 SO ATLAST YOUR OUTPUT WILL BE 8181.
This Is The Easiest Way I Can Explain This To You Vladimir
+ 4
This post will help u to understood the concepts of reference variable
https://www.geeksforgeeks.org/references-in-c/amp/
+ 1
Okay You Want Explanation About How This Code Gave You Output 8181 ?
+ 1
Yes 8181.
+ 1
Int &y=x means that if you increase x or y second also changed since both variables link the same memory. But if you write int y=x in this case you will create copy of x value. So bot variables in this case link to different memory
+ 1
Absolutel right!
First go to memory location x and then print the value of x.
x=81 and y=81.
+ 1
Thanks george I Just Mismatched With Terms
+ 1
Vladimir budut voprosi po c++ pishite v lichku pomogu chem smogu
0
Ryan Daniel not pointer but reference! There are a big difference between pointer and reference
0
Ryan Daniel you are welcome! The great explanation!