Char *foo(){char result[100]);strcpy(result,"anything is good");return(result);}void main(){char *j;j=foo()printf("%s",j);}

Showing Answers 1 - 1 of 1 Answers

ramana

  • Jul 19th, 2006
 

'j' in main method will be pointing to an address in foo()'s stack. You might get "anything is good" in this case but there is no guarantee. In large programs, the address might be overwritten by something else and the result will be garbage. One should avoid returning pointers to stack addresses.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions