#pragma warning(disable : 4996) #include #include using namespace std; class str { public : char* p; int size; str(int sz) { p=new char[size=sz] ; cout << " Constructor &p " << &p << " p = " ; cout << p << endl; } ~str() { cout << " Destructor &p " << &p << " p = " ; cout << p << endl; delete[] p; } str(const str&); }; str::str(const str& c) { cout << " copy constructor \n"; p=new char[size=c.size]; strcpy(p,c.p); } void foo() { str s1(10); strcpy(s1.p,"abcdefghi"); cout << " Address of s1 " << &s1 << endl; cout << " s1.p " << s1.p << endl; cout << " Before creation of s2" << endl; str s2(20); cout << " Before assignment " << endl; s2=s1; cout << " After assignment " << endl; cout << " Address of s1 " << &s1 << endl; cout << " s1.p " << s1.p << endl; return; } int main() { int i; cout << " Program starts \n"; foo(); cout << " Back in main - "; cout << "Type an integer to continue \n"; cin >> i; return(0); }