C Program #3

What is the output of the following C program?

RUN CODE ONLINE
#include <iostream>
using std::cout;
class main
{
public:
	main() {cout << "ctor is called\n";}
	~main() {cout << "dtor is called\n";}
};
int main()
{
	main m; // LINE 11
}

Output

Compiler error:
11 8 [Error] expected ';' before 'm' 

Although the C program in the above sentence appears to be syntactically correct, compilation fails. class name for the reason. The compiler must be informed that main is the name of the class since that is its name. To create an object of a class or struct, the struct or class keyword is typically not necessary to write. However, if the name of the class is main, it is then necessary to write struct or class when creating a class or struct object. Main should not be forgotten as a reserved word.