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 -04:00
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: which one is right?

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论