I have a difficulty in a conceptual problem
consider this code:
char *myfunc()
{
char *temp = "string";
return temp;
}
int main()
{
char* ptr = myfunc();
}
I can't understand why ptr points to "string" after the function call. myfunc() creates an address in the stack which has the value "string" and another address which has the address of "string". When the function ends, the memory it had in the stack is freed so it should return a pointer pointing to an address that does not contain "string" anymore.