Demonstrate how copy constructor is called during pass by value and return by value using C++ programme.
#include <iostream>
using namespace std;
class Test
{
int x;
int y;
int *z;
public:
Test()
{
z=new int;
}
void input(int a,int b,int c)
{
x = a;
y=b;
*z=c;
}
void output()
{
cout << "The value of x is : " <<x<< std::endl;
cout << "The value of y is : " <<y<< std::endl;
cout << "The value of *z is : " <<*z<< std::endl;
}
};
int main()
{
Test t1;
t1.input(20,5,7);
Test t2 = t1;
t2.output();
return 0;
}
Comments
Leave a comment