because i is static.. On Wed, Aug 31, 2011 at 8:23 PM, aditya kumar <[email protected]>wrote:
> @rahul : wen the values are pushed on to the stack they are like 9 , 8 , 7 > , till 0 so when they pop out shouldnt it be follwing the order 0 1 2 till 9 > . i realy dont know why the o/p is 0 -1 -2 and so on ?? > > > On Wed, Aug 31, 2011 at 8:18 PM, rahul sharma <[email protected]>wrote: > >> i thnink it works as follow:- >> >> >> firstly >> loop goes pushing into stack >> printf("%d",i); >> printf("%d",i); >> printf("%d",i); >> printf("%d",i); >> printf("%d",i); >> printf("%d",i); >> printf("%d",i); >> printf("%d",i); >> printf("%d",i); >> >> now i is 1 >> --i >> means --1 >> i=0; >> >> now all printf are poped printing --i >> from 0; >> >> m i ryt????? >> >> >> >> On Aug 31, 7:40 pm, rahul sharma <[email protected]> wrote: >> > these two are same >> > >> > On Aug 31, 7:36 pm, ravi maggon <[email protected]> wrote: >> > >> > >> > >> > >> > >> > >> > >> > > I check out the code: >> > >> > > #include<stdio.h> >> > > main() >> > > { >> > > static int i=10; >> > > while(i>0) >> > > { >> > > --i; >> > > main(); >> > > printf("%d",i); >> > > } >> > >> > > } >> > >> > > if you run this you get 0000000000 as output >> > >> > > but if you run this >> > >> > > #include<stdio.h> >> > > main() >> > > { >> > > static int i=10; >> > > while(i>0) >> > > { >> > > --i; >> > > main(); >> > > printf("%d",i); >> > > } >> > >> > > } >> > >> > > You get 0-1-2-3-4-5-6-7-8 as output. >> > >> > > Whats the difference in these? >> > >> > > On Wed, Aug 31, 2011 at 7:52 PM, aditi garg < >> [email protected]>wrote: >> > >> > > > @abhishek: y till -8? >> > >> > > > On Wed, Aug 31, 2011 at 7:50 PM, vishal jain <[email protected] >> >wrote: >> > >> > > >> I executed on linux machine.. >> > >> > > >> I am gettign output >> > >> > > >> 0-1-2-3-4-5-6-7-8 :( >> > >> > > >> for code >> > > >> int main() >> > >> > > >> { >> > > >> static int i=10; >> > > >> while(--i>0) >> > > >> { >> > > >> main(); >> > > >> printf("%d",i); >> > > >> } >> > > >> return 0; >> > > >> } >> > >> > > >> On Wed, Aug 31, 2011 at 7:48 PM, Abhishek Mallick < >> > > >> [email protected]> wrote: >> > >> > > >>> The recursion will run 10 times printing nothing. Then ones it >> returns >> > > >>> on the 10th one. It will start printing from 0 to -8 (As i is >> static). >> > >> > > >>> On Aug 31, 6:33 pm, ravi maggon <[email protected]> wrote: >> > > >>> > Ans would be 0000000000, keep in mind that i is static variable. >> > >> > > >>> > On Wed, Aug 31, 2011 at 6:59 PM, rohit <[email protected]> >> wrote: >> > > >>> > > 123456789 >> > >> > > >>> > > -- >> > > >>> > > 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/-/OsL6-Vp91qoJ. >> > > >>> > > 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. >> > >> > > >>> > -- >> > >> > > >>> > 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. >> > >> > > >> -- >> > > >> 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. >> > >> > > > -- >> > > > Aditi Garg >> > > > Undergraduate Student >> > > > Electronics & Communication Divison >> > > > NETAJI SUBHAS INSTITUTE OF TECHNOLOGY >> > > > Sector 3, Dwarka >> > > > New Delhi >> > >> > > > -- >> > > > 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. >> > >> > > -- >> > >> > > 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. >> >> > -- > 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.
