I have been programming C for a while (but still pretty new to C) and I am sometimes getting confused of the way the C is handling the memory.
Consider following valid C snippet:
const char *string(void)
{
/* where is this pointer variable located in the memory? */
const char *s;
/* where is this text data located in the memory? */
/* and when the program allocates memory for it? */
s = "Hello, World";
return s;
}
int main(void)
{
printf( "%s", string() );
return 0;
}
I am asking what exactly is going on in the memory? Isn't the pointer variable 's' a local variable or where is the pointer variable stored in the memory. Also where is the text constant "Hello, World" stored in memory (isn't this considered to be local variable which isnt accesible after function returns)?
Basically what kind of variables / data are consider to be in "local" scope of the functions (ceases to be accessible after function returns)?
I hope you understand what I am trying to say :D.. I think I have lot to learn about compilers and executables so feel free enlighten me!