×

Loading...

To whois, blaise and willcome: The problem is : When using the VC++ to compile them, 1, 3 are right without even a warning. 2 is right too with a warning.

But from the article I have read: 3 is wrong too. I am really confused.

) Fairly Easy. What is wrong with the following function? Explain.

char* GetName()
{
return "Bill Clinton";
}

Answer: The string "Bill Clinton" is allocated on the stack and thus deallocated when the function returns. The function returns a pointer that cannot be trusted, aka a bad pointer.
Report

Replies, comments and Discussions: