Varible is different once returned.

This is a discussion on Varible is different once returned. within the C++ Programming forums, part of the General Programming Boards category; Hey there,
I have a varible which is declared inside the scope of a function, of the type const char*. ...

Varible is different once returned.

Hey there,
I have a varible which is declared inside the scope of a function, of the type const char*. If I printf() the varible it's correct value is displayed and then that varible is returned. If I then printf() the varible which was returned (from another function) the value is just scrambled characters. Could anyone suggest why this is happening?
Thanks,
epoch

You can't return a pointer to a local variable and expect the memory to not be reclaimed when the function returns. In other words, this will not work because the memory for s is reclaimed when the function returns: