#include <iostream>
#include <string>
using namespace std;
void reassign(string* & a);
int main()
{
string *x = new string("abcd");
cout <<"x is " << *x <<" at " << x <<endl; //"x is abcd at 0x95b7008"
reassign(x);
cout <<"x is " << *x <<" at " << x <<endl; //"x is efgh at 0x95b7030"
delete x;
return 0;
}
void reassign(string* & a)
{
string *old = a;
a = new string("efgh");
delete old;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCnZvaWQgcmVhc3NpZ24oc3RyaW5nKiAmIGEpOwppbnQgbWFpbigpCnsKICAgIHN0cmluZyAqeCA9IG5ldyBzdHJpbmcoImFiY2QiKTsKICAgIGNvdXQgPDwieCBpcyAiIDw8ICp4IDw8IiBhdCAiIDw8IHggPDxlbmRsOyAgICAvLyJ4IGlzIGFiY2QgYXQgMHg5NWI3MDA4IgogICAgcmVhc3NpZ24oeCk7CiAgICBjb3V0IDw8InggaXMgIiA8PCAqeCA8PCIgYXQgIiA8PCB4IDw8ZW5kbDsgICAgLy8ieCBpcyBlZmdoIGF0IDB4OTViNzAzMCIKICAgIGRlbGV0ZSB4OwogICAgcmV0dXJuIDA7Cn0KCnZvaWQgcmVhc3NpZ24oc3RyaW5nKiAmIGEpCnsKCXN0cmluZyAqb2xkID0gYTsKICAgIGEgPSBuZXcgc3RyaW5nKCJlZmdoIik7CiAgICBkZWxldGUgb2xkOwp9Cg==