I know that the C++ standard says that return 0
is inserted at the end of main()
if no return statement is given; however, I often see recently-wri
Just because your code complies with the standard, who says your code is going to be run through a compliant compiler? Believe it or not, people do use compilers besides just recent versions of GCC and Visual C++.
And of course there's the explicit intent thing that everyone else has mentioned.
I often do it because I often compile code for straight C, so I either type it in out of habit or because the snippet I created main()
from has the explicit return. There's no reason to remove it, so it usually stays.
Then again, there are times when I won't bother typing it in (maybe I realized I didn't need it) or I may have used a different snippet.
Because some people don't know. Not necessarily the people who wrote that code (although that's also possible), but some people out there. Explicitly writing return 0;
is being nice to them.
Also, as a convention it makes the language more uniform, which aesthetically is important to at least me.