I am beginner in C. I have one program as below:
int main()
{
char* func();
char *c;
c = func();
printf("%s", c);
}
char* func()
{
char *ptr = "OK";
return ptr;
}
As we all know, ptr is a local variable of func() and is a pointer. The scope is local.
But when ptr is returned to the caller, main, it is still valid and when c is printed, it prints "OK".
How is this possible? In which memory segment is ptr stored; stack, or heap?