ExamVeda
Login
Home
This question belongs to C Program C Miscellaneous
C Miscellaneous
?

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

Answer & Solution
Correct Answer: Option B

When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively.

Examveda
Question posted by Examveda
Community

Join the Discussion

3 Comments
Afsana Hossain
Afsana Hossain 3 years ago
Can someone explain why the result come 5 4 3 2 1? As it has given a static variable.
511 _Nikhil
511 _Nikhil 5 years ago
I heard that static variables cannot be changed !! Under that case the option should be D?
Smithin Vijayan
Smithin Vijayan 10 years ago
If(var)

var is an int variable ,
If should contain a bool value write?