Multiple choice technology programming languages

main() { static int var = 5; printf("%d ",var--); if(var) main(); }

  1. 1 2 3 4 5

  2. 5 4 3 2 1

  3. compilation error

  4. None

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

The variable 'var' is static, meaning it retains its value between recursive calls of main(). In each call, printf prints 'var' before it is decremented post-evaluation (post-decrement). If 'var' is non-zero after decrement, main() is called again. The sequence printed is 5, 4, 3, 2, 1, stopping when 'var' becomes 0.