Because i is static it is not on the stack. There is one value of i
accessed from all the calls to main. Each time main is called, it
decrements i, then if the decremented value is positive, it calls
main. So eventually we get to the point where we are 10 levels deep
and i=0. Then we have to start unwinding the stack. But even when i is
zero, every time the while condition is evaluated, it will decrement
i. So i continues to be decremented at each level as the recursion
unwinds. That is why it prints negative values.
Don

On Aug 31, 8:20 am, ravi maggon <[email protected]> wrote:
> what will be the output of this:
> main()
> {
>     static int i=10;
>     while(--i>0)
>     {
>          main();
>          printf("%d",i);
>     }
>
> }
>
> --
>
> Regards
> Ravi Maggon
> Final Year, B.E. CSE
> Thapar University

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to