Every time the function f() is called, it allocates an entirely new set of memory location, copies "goodbye" in it and returns its base address. So even if you assign 'A' to its first location, the first character of the array allocated by f() will still be 'g' if you call it the next time Thats what is happening here and you will get output : *g*
Anurag Sharma On Wed, Jun 16, 2010 at 8:56 AM, sharad kumar <[email protected]>wrote: > ya i forgot that...considering that plz explain o/p > i.e > #include<malloc.h> > char *f() > {char *s=malloc(8); > strcpy(s,"goodbye"); > return s; > > } > > main() > { > *f()='A'; > printf("%c",*f()); > } > > -- > 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. > -- 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.
