0

Please give me the output and explain it

#include<stdio.h> int main() { static int i; for(++i;++i;++i) { printf("%d",i); if(i==4) break; } return 0; }

10th May 2020, 11:13 AM
Rihaj Mujawar
Rihaj Mujawar - avatar
6 Answers
+ 1
You do realise it's a 2 and a 4 not 24.
10th May 2020, 11:46 AM
rodwynnejones
rodwynnejones - avatar
0
Output is 24 but why ?
10th May 2020, 11:17 AM
Rihaj Mujawar
Rihaj Mujawar - avatar
0
I think so but how it is possible
10th May 2020, 2:53 PM
Rihaj Mujawar
Rihaj Mujawar - avatar
0
The i starts off with a value 0; In the for loop: In the first section of the for loop.....i is incremented...so i = 1. Then the second portion is evaluated for a true of false...but i is incremented again in there...now i = 2...so the condition is true..i.e not 0. The action statements in your for loop are then executed.....output = 2 then the i is incremented in the third portion...i = 3. Then...the condition (the second portion) is evaluated again....but i is incremented again in there....i = 4....now it prints 4 and breaks because of the if test is true.
10th May 2020, 3:50 PM
rodwynnejones
rodwynnejones - avatar
0
I think you forgot one step after i=3 it's increment in first step hence i=4 and in 2nd it check and increment i=5
10th May 2020, 4:24 PM
Rihaj Mujawar
Rihaj Mujawar - avatar
0
Please explain again
10th May 2020, 4:24 PM
Rihaj Mujawar
Rihaj Mujawar - avatar