in first one when fun(200) is called it goes to else part and calls fun(fun(199)) => fun(199) is reurns 199 and so we have fun(199) which returns 199 as the answer
second case fun(200) is called it goes to else part and calls fun(fun(199)) =>fun(199( is called which returns200 and so we have fun(200) .. This is now recursive non changing call which will eat up stack space and hence cause segenttaion fault --mac On Sat, Nov 13, 2010 at 10:23 PM, sudhir mishra <[email protected]>wrote: > *1st programe give output:199 but 2nd give Segmentation fault why* onle > change in return------------ > > *1)* int fun(int i) > { > if ( i%2 ) *return (i++);* > else return fun(fun( i - 1 )); > } > int main() > { > printf(" %d ", fun(200)); > getchar(); > return 0; > } > > *2) *int fun(int i) > { > if ( i%2 ) *return (++i);* > else return fun(fun( i - 1 )); > } > > int main() > { > printf(" %d ", fun(200)); > getchar(); > return 0; > } > > > > -- > -- > regards > *Sudhir Mishra* > MNNIT ALLAHABAD > > > -- > 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]<algogeeks%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- thanks --mac -- 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.
