Main Loop Question

i was just wondering why most people use int main() and then return 0. why not just make it void main(). is it just good practice or for the "fun" of it. I realize that you can make it return 1 if it fails or something like that, but it seems like most just return 0 with no "else"
The reason for using int main() and returning 0 is that it makes future enhancement simpler.
The return value for main can be checked but a calling script / batch file, etc - zero indicates success. Non-zero indicates a failure of some sort.
By always using int main() you are standardising, and allowing yourself to extend the program in future to retun failure codes without requiring users to alter the general structure of their scripts.
I believe that the C++ standard specifies that main() must return int for all the reasons Faldrax mentioned.
Ok, thats good to know. Thank you
The standard states clearly that main has to return int. Otherwise you invoke undefined behavior. You don't have to use an explicit return-statement in main, though - if control reaches the end of the function, 'return 0' is implicitly executed.
Topic archived. No new replies allowed.