What is the output of this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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?

22nd May 2024, 2:23 AM
Moon
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.
22nd May 2024, 4:46 PM
Brian
Brian - avatar
+ 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
22nd May 2024, 2:49 AM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 1
Oww... Now I get it.. Thank u. 「HAPPY TO HELP」
22nd May 2024, 3:53 PM
Moon