Function returning a structure and function returning a string-- Different behaviour?
I have heard that we cannot return a pointer to a local (automatic) array variable from a function since the automatic variable have limited scope and they die off once the called function returns.
But a doubt arises in my mind:
char *s getName()
char name="Sumit"; // Automatic variable
retrun name; // No scope outside the function
here also we are returning a reference to a memory location which is allocated locally. Then how come here it works perfectly fine.
struct info getInfo(int a,int b)
struct info f1; // Automatic variable memory allocated for a structure
Waiting for reply