Find factorial of a number using copy constructor
Q. Write a C++ program to find the factorial of a number using copy constructor.
Constructor is a special type of member function which initializes an object automatically when it is created. It has same name as class name. Constructor does not have return type.
Copy constructor is a special type of constructor which takes an object as an argument. It is used for creating the second object.
Following program is calculating the factorial of a number using copy constructor.
using namespace std;
int n, i, facti;
fact(int x) //copy constructor
for(i=1; i<=n; i++)
cout<<"\n Factorial : "<<facti;
cout<<"\n Enter Value : ";
fact f2(f1); //copy constructor takes an object as an argument.