I have a simple program
const char* returnString()
{
std::string s = "Hello";
return s.c_str();
}
int main()
{
const char* stemp = returnString();
return 0;
}
when my optimization flag value is /O2 stemp will have value "Hello", but when i dont have any optimization flag, stemp will be empty(which i felt is expected behavior no??). What exactly happens with /O2 that it get the value correctly? i tried seeing Disassembly, i saw the differences but i am not much knowledgeable there so i did not understood much there