Technical Discussion :: C++
Home > Freshers > Technical Interview Questions > C++
30. What is Copy Constructor? Write a program using it.
Answer:
Copy constructor is used to declare and initialize an object from another object.
For example, the statement
Integer I2(I1);
Would define the object I2 and at the same time initialize it to the values of I1. another form of this statement is integer I2=I1;
The process of initializing through a copy constructor is known as copy initialization. A copy constructor takes a reference to an object of the same class as itself as an argument.
Asked In :: Capgemini Syntel Inc. Societe Generale
Copy constructor is used to declare and initialize an object from another object.
For example, the statement
Integer I2(I1);
Would define the object I2 and at the same time initialize it to the values of I1. another form of this statement is integer I2=I1;
The process of initializing through a copy constructor is known as copy initialization. A copy constructor takes a reference to an object of the same class as itself as an argument.
For example, the statement
Integer I2(I1);
Would define the object I2 and at the same time initialize it to the values of I1. another form of this statement is integer I2=I1;
The process of initializing through a copy constructor is known as copy initialization. A copy constructor takes a reference to an object of the same class as itself as an argument.