Multiple choice

What is the output of the following C code?

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

  1. Infinite loop

  2. Compilation error

  3. Runtime error

  4. 1

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The basic thing that we need to remember in C is that zero means false. Now, the code inside for loop as condition is checked. Variable i is zero since we are using post-increment operator. Hence, loop is terminated and after that 1 is printed which is the final value of i. Therefore, this is the correct answer.