For the following program:
#include<stdio.h>
char *getString()
{
char *str = "GfG";
return str;
}
int main()
{getString();
printf("%s", str); // Gives error, but printf("%s", getString()); works perfect.
return 0;
}
My doubt is that if we're able to return str as it is present in the shared segment of the memory and it's activation record does not get destroyed, wh can't we print the value using str? Why does the program give error saying that str is undeclared?