Copy Constructor creates an object by initializing it with an object of same class.
Program:
#include<iostream>
using namespace std;
class code
{
int id;
public:
code()
{
}
code(int a)
{
id=a;
}
code(code &x)
{
id=x.id;
}
void display()
{
cout<<id;
}
};
int main()
{
code a(100);
code b(a);
code c=a;
code d;
d=a;
cout<<"\n\n\n\t copy constructor";
cout<<"\n\n\n\t ****************";
cout<<"\n\n\t a=";
a.display();
cout<<"\n\n\t b=";
b.display();
cout<<"\n\n\t c=";
c.display();
cout<<"\n\n\t d=";
d.display();
return 0;
}
OUTPUT:
BY
REGU RAM SV.
Post a Comment