@muthu
each time the while condition evaluates, the variable is decremented
and a recursive call to main is executed if it's true. when the
condition is finally false, the last function call ends without
printing, returning to the previous call on the stack, which does the
print then hits the end of the while loop. The while loop HAS to check
the condition again to know if it should loop or not, which results in
another decrement because the -- is inside the condition.
If the code was
while (i > 0) {
--i;
main();
printf("%d",i);
}
then the counter would only be decremented on a true while condition
check, resulting in all 0's being output (static becomes 0 on the
final recursive call, then is no longer decremented because all
further while condition checks are false and do not enter the while to
decrement it further).
On Aug 31, 11:49 am, muthu raj <[email protected]> wrote:
> can u tell y negative values are gettin printed? when recursive calls
> return y is condition checking done again?
> *Muthuraj R
> IV th Year , ISE
> PESIT , Bangalore*
>
>
>
>
>
>
>
> On Wed, Aug 31, 2011 at 9:14 AM, Sanjay Rajpal <[email protected]> wrote:
> > Thank u swathi for making me clear about static variables.
>
> > Sanju
> > :)
>
> > On Wed, Aug 31, 2011 at 9:10 AM, Swathi <[email protected]> wrote:
>
> >> Google it.. you will find the answer,
>
> >>http://www.velocityreviews.com/forums/t443436-where-is-a-static-varia...
>
> >> On Wed, Aug 31, 2011 at 9:35 PM, Sanjay Rajpal <[email protected]> wrote:
>
> >>> Static variables are always stored in the data section.
>
> >>> Sanju
> >>> :)
>
> >>> On Wed, Aug 31, 2011 at 9:04 AM, Swathi <[email protected]> wrote:
>
> >>>> C standard doesn't define where static variables has to be stored. All
> >>>> it says is to persist the data across the multiple function calls. So I
> >>>> think the answer varies based on the compiler implementation but printing
> >>>> all zeros makes more logical.
>
> >>>> On Wed, Aug 31, 2011 at 9:25 PM, rohit <[email protected]> wrote:
>
> >>>>> +1 to chris
>
> >>>>> --
> >>>>> You received this message because you are subscribed to the Google
> >>>>> Groups "Algorithm Geeks" group.
> >>>>> To view this discussion on the web visit
> >>>>>https://groups.google.com/d/msg/algogeeks/-/fzTBEIWLGcAJ.
>
> >>>>> 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.
>
> >>>> --
> >>>> 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.
>
> >>> --
> >>> 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.
>
> >> --
> >> 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.
>
> > --
> > 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.
--
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.