It is not. You have allocated one character on the free store and given its address to e. Then you have reassigned e to the string literal "hello", which exists in memory allocated by main(). Then you, via the function return, assigned the "hello" address to f. Printing f will print "hello", but you have done little but confuse yourself. No offense. Check it out:
Code:
char* foo(char* str)
{
//Find out how big the string referred to by str is.
//That is, write your own strlen implementation.
//Then,
unsigned int len = MyStrlen(str);
char* returnable = new char[len];
//Copy, character by character, the contents of str into returnable.
//That is, write your own implementation of strcpy.
//Then,
return returnable;
}
int main()
{
const char* lit = "hello";
char* f = foo(lit); ///const trouble? I'm not sure.
std::cout << f << " is a copy of " << lit << std::endl;
delete [] f; //so easy to forget... your program has a leak, by the way.
return 0;
}