What is the output of this C code?
int main()
{
int i = 0;
for (foo(); i == 1; i = 2)
printf("In for loop\n");
printf("After loop\n");
}
int foo()
{
return 1;
}
Answer: A
Correct answer: After loop
The initialisation foo() is evaluated once and its value discarded, so the 1 it returns changes nothing. The condition i == 1 is then tested with i still 0, which is false, so the body never runs - only After loop is printed.
Please log in or register to report this question.