What is the primary purpose of a constructor in a class?
- To delete instances of a class.
- To declare variables.
- To initialize object properties.
- To control memory allocation.
A constructor is a special member function of a class that is executed whenever a new object of that class is created. Its primary role is to initialize the attributes or properties of the class, ensuring that the object starts its life in a controlled state.
Loading...
Related Quiz
- Which function is used to get the position of the file pointer in a file?
- Which operator will give the remainder of a division operation?
- To check for possible errors or failures in file operations, you should check the _______.
- In C++, the data type _______ is commonly used to store large integers.
- What will be the output of a loop if the continue statement is placed before the print statement inside the loop?