#include <string>
#include <iostream>
const char* my_concat(const std::string& s1, const std::string& s2)
{
std::string str = s1 + s2;
return str.c_str();
}
int main()
{
using namespace std;
cout << my_concat("hello ", "world");
return 0;
}
Q1: Who deallocates the const char* string returned from my_concat?
Q2: With the local str destroyed, why isn't str.c_str() invalidated?
Q3: In general, how is the C string from string::c_str() allocated and
manged?
ben