void main()
{
static int a=4;
printf("%d",a--);
if(a)
main();
}
what'll be the answer?
- run continuously
- compile time error
- print 3 2 1 0
- print 4 3 2 1
For Static variable, memory is statically allocated .
At first a is declared and initialize to 4 .
a=4 is printed and then a is decreament to 3.
Then if(a) will work main will called itself . But note that now a is 3. Then it'll print 3 and a is decreament to 2. Like that it 'll print 4 3 2 1. When a=0 then if(a) is false . So it won't call main function.