Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
What is a copy constructor? Give a suitable example in C++ to illustrate with its definition within a class and a declaration of an object with the help of it .
Answer:
A copy constructor is an overloaded constructor in which an object of the same class is passed as reference parameter.
class Point
{
int x;
public:
Point(){x=0;}
Point(const Point &p) // Copy constructor
{x = p.x;}
};
void main()
{
Point p1;
Point p2(p1); //Copy constructor is called here
//OR
Point p3=p1; //Copy constructor is called here
}
C. Sir| Created: 4-Jan-2019 | Updated: 22-Mar-2026|CBSE12D-2015