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.

guest (guest)
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.
2001-5-15 -05:00

回到话题: which one is right?

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论