+ 4
can anyone explain this output? int x=3; x=++x + x++; cout<<x; //output=9
4 Answers
+ 4
In that statement first x stores the value 3 then run next statement (x=++x + x++).in the statement x assign the value 8 (4+4) after that it increment once again due to post increment of x.so finally it gets 9 as the value in x.
- 2
first the ++x makes ur x equals 4 then the x++ makes x= 5 (first 'x' stores the value 3 in the beginning and then 'x' becomes 4 and then the value again increases by 1 then it becomes 5)
So the sum 4+5 becomes 9.
I think it might help you out.
- 2
1. 3=(1+3)+(3+1)
2. 4=(4)+(4+1)
3. 9=4+5
- 5
in above expression solve right to left so first x++ value x is 4 then ++x value is 5 and add them 5+4=9.
there is concept of sequence point