+ 1
Exam question
İnt main () {int a=1 , b=2 , x; while (a + b == 3) { do { b++ ; x = a + b ; } while (b == 3 ) ; } printf("%d\n , x) ; } Answer is 5, can you explain this?
1 Réponse
+ 2
Pythontutor.com has a nice visualization tool (also for C). Paste the code there and read those comments while you do that:
In the code there is a do/while loop nested inside a while loop. The while loop executes once because a+b == 3 a the start. The do/while executes once for the "do" and once because b == 3 after that. On pythontutor you can nicely see hwo that brings x to 5.