Registered: 13 years ago
The following program defines a function that is supposed to return a pointer of a string variable to the main program. Strangely, the program compiles but crashes when it runs. It crashes where it attempts to derefrerence the pointer in the main program.
"Local variables are destroyed and their memory reclaimed at the end of the enclosing block." - cprogramming.com
That means that you are making reference to a memory location that does not exist anymore. One way to get around this is to use a global variable as in the next example.
using namespace std;