New course! Every coder should learn Generative AI!
Try a free lesson0
What is the output of this code?
int x = 3; while (x++<10){ x+=2; } cout <<x; After the 3rd iteration isn't the result comes 12?? . I got this code in Sololearn Challenge.. The correct answer shows 13. Can anyone explain?
3 Answers
+ 4
Moon you are allowed to try out the code yourself in the Code Playground to see what its output will be. Insert cout statements to see how the variables change inside the loop.
+ 3
x is checked then later incremented
x++<10 x => 4
x += 2 x => 6
x++<10 x=> 7
x += 2 x => 9
x++<10 x => 10
x += 2 x => 12
x++<10 x => 13
FALSE NO MORE += 2
+ 1
Oww... Now I get it.. Thank u. 「HAPPY TO HELP」