0
I wonder why output is 13?
int x = 3; while (x++<10) { x += 2; } cout <<x; return 0;
4 Answers
+ 2
1st iteration:
x++<10 => 3<10 true, x++, x=x+1
x=4, x+=2=> x=6,
2nd:
x<10 => 6<10 true, x++, x=7,
X+=2 =>x=9
3rd:
X<10 =>9<10, true, x++=>x=10
X+=2. =>x=12,
4th:
X<10=> 12<10 false, loop stops, x++ =>x=13
X++, Post increment first uses the value then increments... So answer is 13
Hope this helps you....
+ 1
The condition will be ran 1 more time than the code block.
0
x=3, then x++ == x = x +1 so x=4
4 < 10 so 4 + 2 = 6
Why output is 13???
0
Thank you very much! Yeah! I get it!