Sunday, 25 August 2013

What is the reason for this output?

What is the reason for this output?

I have the following code.
int x=80;
int &y=x;
x++;
cout<<x<<" "<<--y;
The output comes out to be 80 80. And I don't understand how. I thought
the output of x would be 81 although I don't know anything about y. How is
the reference variable affected by the decrement operator. Can someone
please explain?

No comments:

Post a Comment