0

can someone explain this ?

int main() { int x=3; while(x++<10){ } cout<<x; //output 11 return 0; }

10th Apr 2019, 9:30 AM
San Anemos
San Anemos - avatar
1 Answer
+ 11
The 'cout' is outside the loop, 'x++ < 10' becomes false (and loop stops) at '10 < 10', but the post-increment is adding 1 after that line of code so you end up having 11. post-increment adds 1 after the instruction while pre-increment adds immediately/before.
10th Apr 2019, 9:37 AM
Valen.H. ~
Valen.H. ~ - avatar