Data Type MCQ 2 : Static Storage Class and Printing Variable



In C Programming (Multiple Choice Question 2 ) Static Storage Class


#include<stdio.h>
void main()
{
static num = 4;
printf("%d ",--num);
if(num)
   main();
}

Options : 

  1. 43210
  2. 3210
  3. Infinite Times 4
  4. Compile or Run Time Error


Why & How ?

  • Pre Increment : Refer Here
  • Storage Class is Static
  • Static Storage class in initialized Once
  • Static Storage class can be Modified number of times
  • During Execution Static num is Initialized to 4.
  • We are printing number as (–num) i.e [ First Decrement then Print ]
  • During Second Call to Main Value of num is 3 instead of 4.