What is a constructor in C++?
20 views
- A function that is used to create objects of a class. (Correct Answer)
- A function that is used to destroy objects of a class.
- A function that is used to copy objects of a class.
- A function that is used to compare objects of a class.
Explanation
Correct answer: a) A function that is used to create objects of a class.
Explanation: A constructor in C++ is a special member function that is called when an object of a class is created. It is used to initialize the object`s data members and perform any other necessary setup.