char *fun()
{
char *tmp = “SOME TEXT”;
return tmp;
}
void main()
{
puts(fun());
}
char *fun()
{
char *tmp = “SOME TEXT”;
return tmp;
}
void main()
{
puts(fun());
}
u need to use char pointer
char* fun()
{
const char* tmp="SOME TEXT";
return tmp;
}
void main()
{
puts(tmp);
}
char* fun()
{
const char* tmp=“SOME TEXT”;
return tmp;
}
void main()
{
puts(fun());// temp cant be used here
}
use pointer to store the value of string…
some garbage value is printed (or maybe segfault) since “temp” is destroyed as soon as we go out of its scope(which is function;s scope), so “temp” cant be accessed outside