+ 1
Why is it necessary to have main function ?
Why is there a default function in c++ . Why not a default variable or class also ???
4 ответов
+ 8
This is because main() represents the entry point to your program. It is where your program begins to run. As for variables and classes, there may be cases wherein your program can run without variables or classes. However, for a program to exist, an entry point is required.
+ 3
As other said, it's the specific entry point, which isn't always main. For example, it's called DriverEntry for windows drivers
+ 2
The execution starts from main function.
Before calling main function the Kernel calls a special method which will assign the starting address of execution as the main function.
The editor will communicate with kernel and finds if any initialization are there and initializes and calls the main function.
This is the process of execution of a program,so it is required to have main function .