+ 9

Output of this fragment of code. Explain the the output how it works , what could be answer.

int i=0; for(;i<=5;i+=4); {i=i*i;} printf("%d",i);

22nd Apr 2020, 12:27 AM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
4 Answers
+ 2
i<=5 i first equals 0 so for loop is entered i = 0 * 0 i += 4 i now equals 4, still less than 5 loop again i = 4 * 4 i equals 16 I += 4, i now equals 20, greater than 5 loop exits printf("%d", i) output value of i 20
22nd Apr 2020, 12:56 AM
ChaoticDawg
ChaoticDawg - avatar
+ 6
Thank you , i was looking for this thing.
22nd Apr 2020, 2:26 AM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 5
It is producing output as 20,,,, how????
22nd Apr 2020, 12:48 AM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 2
That code won't compile, it has a few errors. 1 semicolon after closing parentheses of for statement. 2 lack of semicolon after last i in code block 3 improper use of print % See code below #include <stdio.h> int main() { int i=0; for(;i<=5;i+=4) { i=i*i; } printf("%d",i); return 0; }
22nd Apr 2020, 12:43 AM
ChaoticDawg
ChaoticDawg - avatar