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; }
6 Answers
+ 1
You do realise it's a 2 and a 4 not 24.
0
Output is 24
but why ?
0
I think so but how it is possible
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.
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
0
Please explain again