Why the address of temp and res are same? In function of version1. I think variable temp will copy to a temporary variable. The temporary variable will copy to variable res. But in result the address of temp and res are same. what optimization the compiler has done?
string version1(const string&s1, const string& s2){
string temp= s2 + s1 + s2;
cout<<"temp in version1 address :"<<&temp<<endl;
return temp;
}
string s1 = "hello";
string s2 = "world";
string res = version1(s1, s2);
cout<<&res<<endl;