Possible Duplicate:
return statement vs exit() in main()
I’ve just read the first chapter of Accelerated C++ (seems like an awesome book), and at the end the author says
However, explicitly including a return from main is good practice.`
Why is this considered good practice? In C99, I always omitted the return 0, using exit() to signal abnormal program termination, and never missed the explicit return.
In C99 and in C++ if execution of the program reaches the closing brace of the
main()function then an implicitreturn 0;is executed. That wasn’t the case in C90 – reaching the end ofmain()without an explicitreturnwould result in an indeterminate value being returned (strictly speaking, the behavior is undefined).I can only guess that the authors of “Accelerated C++” feel that the explicit return is good practice simply because it makes your intent explicit. The only other reason I can think of is that it makes code compatible with C90, but I find it difficult to believe that that would hold much weight as a reason.