#include int count=0; class abc { public: abc(); abc(const abc& a); ~abc(); int i; }; abc::abc() { i=count; count++; cout << "default constructor (Object " << i << " created)" << endl; } abc::abc(const abc& a) { i=count; count++; cout << "customized copy constructor ("; cout << "copying from Object " << a.i << " to Object " << i << ")" << endl; } abc::~abc() { cout << "Destructor (Object " << i <<" destroyed)"<< endl; } abc k1(abc &a) { cout << "Inside k1" << endl; cout << "Before returning something" << endl; cout << "The returning variable would be created by copy constructor"; cout << endl; return a; } abc k2(abc a) { cout << "Inside k2" << endl; cout << "notice: Object " << a.i << " is a" << endl; cout << "Before returning something" << endl; cout << "The returning variable would be created by copy" << " constructor" << endl; cout << "'a' (Object " << a.i << ") would be deleted when this " << "function ends, because it was created as a result " << "of pass-by-value"; cout << endl; return a; } void main() { cout << "Main Begins" << endl; abc h0; cout << "Before calling k1" << endl; k1(h0); cout << "The return variable is not stored and destroyed" << endl; cout << endl; { //scope X cout << endl; cout << "Entering Scope X " <i << ") which is pointer to by p1 would not be deleted " << "because it is created as dynamic variable" << endl; cout << "End of this scope X" << endl; } cout << endl; cout << "h0 (Object " << h0.i << ") would be deleted after the main scope ended" << endl; cout << "End of this main scope" << endl; }