+ 2
What is the use of main() and why is it compulsory??š¤
5 Answers
+ 3
the main function is the driver code of the whole c++ program. It indicates the starting point of instructions when the program is executed.
+ 2
About main function
C language
https://en.cppreference.com/w/c/language/main_function
C++ language
https://en.cppreference.com/w/cpp/language/main_function
+ 1
In C++, theĀ āmain()āĀ functionĀ is treated the same as everyĀ function. The only difference is that theĀ main functionĀ isĀ ācalledāĀ by theĀ operating systemĀ when the user runs the program.
It is used as entry point of program. Every program starts execution from main() function. Like, other function it has alsoĀ return typeĀ andĀ parametersĀ orĀ signatures. By default, return type of main() in C programming language isĀ voidĀ and for C++ isĀ int.
+ 1
The main is the first executable statement for every programming language
From main we can call various userdefined functions or create code based on requirement