Temporary and expression behavior
问题 Is this well defined behavior? const char* p = (std::string("Hello") + std::string("World")).c_str(); std::cout << p; I am not sure. Reasons? 回答1: No, this is undefined behavior. Both std::string temporaries and the temporary returned by operator+ only live until the end of the initialization of your const char* (end of full expression). Then they are destroyed and p points to uncertain memory. 回答2: No the behaviour is undefined because p points to deallocated storage in std::cout << p; A