Multiple choice

Find out the output of the given program or error if any.

static int i=10;  
i=20;             
 int main()
{     
printf(%d,i);     
return 0;
}

  1. 10

  2. 20

  3. 0

  4. Garbage value

  5. Compilation error

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

There is an error in the program, it will not show any output as when we write i=20 in the global scope, it is considered as a declaration and not just an assignment and the compiler assumes it as int i=20. Hence the compiler reports an error that there is a non-static declaration of 'i' after the static declaration of i, which is not allowed. So this option is correct.