Question discussion

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

279645Medium 1 reply 1,092 views
0
Determine Output:void main(){ static int var = 5; printf("%d ", var--); if(var) main();}
  • A5 5 5 5 5
  • B5 4 3 2 1
  • CInfinite Loop
  • DNone of These
Correct answer: B

Discussion 1

0
CCommunity
5 4 3 2 1

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.