|
Subject:
|
C++ and main for a beginner
|
|
Posted By:
|
fords4me78
|
Post Date:
|
1/27/2006 4:13:05 PM
|
Do you have to end every C++ program with "void main()" or can you end it with anything as long as it calls the other functions in the code? Only reason I ask is I left it out and the compiler would not compile without it.
 Craig
|
|
Reply By:
|
Alan-LB
|
Reply Date:
|
1/27/2006 10:05:44 PM
|
main() is the main function of all C and C++ programs so it must be in your program.
Any elementary textbook will explain this
Alan
|
|
Reply By:
|
merediths
|
Reply Date:
|
2/27/2006 8:32:49 PM
|
Well, you could be tricky w/ the linker and name it something else if you were *really* determined too, but essentially, yes, every ANSI/ISO compliant program must contain a main() function ... not that sometime auto-generated code, for example Win32 project code created by the Visual C++ 5/6 IDE does *not*, however it has a main() funtion in the standard libraries it imports for you.
HOWEVER you do NOT need to *end* your program in main(). your "void main()" can go anywhere in your program you like ... AFAIK the ending your program w/ main() was an old Pascal convention. I like to have my main() function at the beginning of the file it's in, but that's just personal preference.
Regards, Meredith Shaebanyan
|