You are here:

C++/main() function !

Advertisement


Question
why we write main function at the starting of program?


Answer
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 : princeatapi@yahoo.co.in

Thanks and Regards !
Prince M. Premnath

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise

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

Experience

More than 5 years

Education/Credentials
MCA

©2016 About.com. All rights reserved.