hi everybody,
these two codes returns pointer to an object declared and defined within the function. yet both of them prints the correct value of the variable c in main(the values of variable c should have been destroyed when the call is over.).
the first code gives the warning.
but second do not..(all compilations in g++ )
const char *f()
{
char c;
cout<<"enter : ";
cin>>c;
return &c;
}
int main()
{
const char *c = f();
cout<<"the value is "<<*f()<<endl;
}
const char *f()
{
return "hello world\n";
}
int main()
{
const char *c = f();
cout<<c<<endl;
}
please help.....
thanx.....