Multiple choice general knowledge science & technology

void main() { i=50; printf("%d",i); } What should be added to this file, so that the program is compiled.

  1. int i; /*above main() */

  2. extern int i; /*inside main() */

  3. Both 1 & 2

  4. option 3 if i is defined elsewhere.

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

The code uses variable 'i' without declaring it. Options 1 and 2 alone are insufficient. Option 3 (declaring i as extern inside main) requires i to be defined elsewhere globally - that's what D specifies, making it correct.