0

Explain the code

When it comes to 3 it terminate .But the output is 2

25th Mar 2020, 9:40 AM
Ajith
Ajith - avatar
6 Antworten
+ 1
Ajith are you sure that this is the exact code? Because the output is coming out to be 54 just like it should.
25th Mar 2020, 9:45 AM
XXX
XXX - avatar
0
int cnt=5; while(cnt>=0){ if(cnt==3) break; printf("%d \n",cnt); cnt--; } Output is 2
25th Mar 2020, 9:42 AM
Ajith
Ajith - avatar
0
The output should be 54. And 2 numbers are printed.
25th Mar 2020, 9:45 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Damn sure
25th Mar 2020, 9:46 AM
Ajith
Ajith - avatar
0
Run the code again, the output is 54. First iteration: cnt = 5 So 5 is printed Second iteration: cnt = 4 So 4 is printed without line break. Third iteration: cnt = 3 The loop breaks
25th Mar 2020, 9:48 AM
XXX
XXX - avatar
0
Okie I got thank you much
25th Mar 2020, 9:50 AM
Ajith
Ajith - avatar