fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5.  
  6. void reassign(string* & a);
  7. int main()
  8. {
  9. string *x = new string("abcd");
  10. cout <<"x is " << *x <<" at " << x <<endl; //"x is abcd at 0x95b7008"
  11. reassign(x);
  12. cout <<"x is " << *x <<" at " << x <<endl; //"x is efgh at 0x95b7030"
  13. delete x;
  14. return 0;
  15. }
  16.  
  17. void reassign(string* & a)
  18. {
  19. string *old = a;
  20. a = new string("efgh");
  21. delete old;
  22. }
  23.  
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
x is abcd at 0x98c9008
x is efgh at 0x98c9030