+ 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 ???

26th Jul 2017, 4:48 AM
Milkha_Da_Techie
Milkha_Da_Techie - avatar
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.
26th Jul 2017, 4:52 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
As other said, it's the specific entry point, which isn't always main. For example, it's called DriverEntry for windows drivers
26th Jul 2017, 5:26 AM
aklex
aklex - avatar
+ 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 .
26th Jul 2017, 5:24 AM
Prasad K G
Prasad K G - avatar