You are here:

C++/main() function !


why we write main function at the starting of program?

Hi dear Chandana !

Its not much essential that main() function to be the starting of the program , perhaps you can define any number of functions just like this !

void foo()
/* some definitions */
void foo2()
/* some definitions */

void main()
 foo(); /* explicit call to foo() */

Given above example apparently shows that main() function is not written at the starting of the program , yet this program will compile without any errors! , your argument is worth if your statement is "why execution starts from main()?"

in this program both main() and foo() , foo2() are user defined functions  , our compiler is not much intelligent ,  from where to start the fly ! So to avoid this situation C programming is devised  in such a way it should start its execution from the main() function no matter how many function you have written in your program!

For more quires feel free to post a follow up !
Mail :

Thanks and Regards !
Prince M. Premnath


All Answers

Answers by Expert:

Ask Experts


Prince M. Premnath


Years of research in C/C++ Will bring you all facts regarding , OOPS , SVGA , MOUSE , BIOS , IVT , Feel free to query me :-)


More than 5 years


©2016 All rights reserved.