I have the next code:
const char* justReturn()
{
std::string s = "rstring";
return s.c_str();
}
int justReturnI()
{
int x = 5;
return x;
}
int main()
{
const char* result = justReturn();
int result2 = justReturnI();
std::cout << result <<std::endl;
std::cout << result2;
std::cin.get();
return(0);
}
The output of the first function eill be a strange string, while the second will gives me '5'.
Why strange characters printed out? I didnt returned the string which died just after the end of the scope. I returned a new const char.