#include using namespace std ; class Demo { private: int z1 ; public: int x1 ; int x2 ; string name ; int* ptr ; Demo(string nameP ) { name = nameP ; cout << "Inside the construtor method."<< name << endl ; ptr = new int[10] ; } Demo(const Demo& demoObj ) { cout << "Inside the copy constructor method." << demoObj.name << endl ; ptr = new int[10] ; name = demoObj.name ; //We have access to another object of the same class's //private data. x1 = demoObj.z1 ; } ~Demo() { cout << "Inside the destructor method:" << name << endl ; delete[] ptr ; } }; Demo function1( ) { Demo obj2("function1") ; obj2.x1 = 100 ; cout << "Inside function1" << endl ; printf( "Address of obj2: %p\n" , &obj2 ) ; return obj2 ; } int main() { { Demo demo1("Local1" ) ; cout << "Step1:" << endl ; //Demo demo2 = function1( ) ; function1() ; cout << "Step2" << endl ; //printf( "Address of demo2: %p\n" , &demo2 ) ; } }