Coupon Accepted Successfully!


main() as a Constructor and Destructor

We learnt that the constructor and destructor have the same name as their class. To use main() as a constructor and destructor, we need to define class with the name main. So far, we have declared object of classes without using the keyword class or struct because C++ treats classes like built-in data types. The use of keyword class or struct is only compulsory when the class name is main. This is because execution of program starts with the function main(). The following program clears this point.


9.23 Write a program to declare class with name main.

Explanation: In the above program, the class is declared with the name main. Hence, it is compulsory to use keyword class or struct while declaring objects.


Tip: When the class name is main, it is compulsory to use keyword class or struct to declare objects.

Test Your Skills Now!
Take a Quiz now
Reviewer Name