πŸ“Š C Programming
Q. Determine Output:
Code:
void main()
{
      static int var = 5;
      printf("%d ", var--);
      if(var)
            main();
}
  • (A) 5 5 5 5 5
  • (B) 5 4 3 2 1
  • (C) Infinite Loop
  • (D) None of These
πŸ’¬ Discuss
βœ… Correct Answer: (B) 5 4 3 2 1

Explanation: 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.

Explanation by: Prashant
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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
175
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Prashant
Publisher
πŸ“ˆ
80%
Success Rate