self
Company
Programming
Program
main()
{
int i=0;
for(;i++;printf("%d",i));
printf("%d",i);
}
Read Solution (Total 1)
-
- for(initializer;condition;'increment/decrement')
A for loop will quit iteration when the condition is false (or a break is issued explicitly).
Here, initially i=0.
The conditional part of for loop i is post incremented so the value there will be 0(false) hence loop will terminate there only even without issuing the print statement of the 'increment/decrement' part of the for loop.
Then in the next statement, incremented value of i will be printed which is 1.
hence the output of this code block must be 1 .
Also if in the above code the conditional part was ++i then program must have gone for infinite loop - 10 years agoHelpfull: Yes(2) No(0)
self Other Question