//#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; } }; void bar(str fred) { cout << " Fred does not have the address of " ; cout << " the string in the calling function" << endl; cout << " Address of fred " << &fred << endl; cout << " fred.p " << fred.p << endl; cout << " bar going out of scope - "; cout << " a destructor will be called " << endl; } void foo() { str s1(10); strcpy(s1.p,"abcdefghi"); cout << " Address of s1 " << &s1 << endl; cout << " s1.p " << s1.p << endl; bar(s1); 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 - Type an integer to continue \n"; cin >> i; return(0); }