What is the output of this code? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
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 Respuestas
+ 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
„ÄĆÔľ®Ôľ°ÔľįÔľįÔľĻ ÔľīÔľĮ Ôľ®Ôľ•Ôľ¨Ôľį„Äć
„ÄĆÔľ®Ôľ°ÔľįÔľįÔľĻ ÔľīÔľĮ Ôľ®Ôľ•Ôľ¨Ôľį„Äć - avatar
22nd May 2024, 3:53 PM
Moon