C++/main() function !
Expert: Prince M. Premnath - 12/17/2007
Questionwhy we write main function at the starting of program?
AnswerHi 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 : princeatapi@yahoo.co.in
Thanks and Regards !
Prince M. Premnath