Multiple choice

What will be the output of the following function?

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

  1. Error

  2. 5 5 5(Infinite times)

  3. 5 4 3 2 1

  4. None of these

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

The static variable 'var' is initialized once and retains its value across recursive calls. Each call to main prints the current value and decrements it, continuing until 'var' reaches 0, resulting in the sequence 5 4 3 2 1.