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-written, standard-conforming C++ code that explicitly returns 0 at the end of main()
. For what reasons would somebody want to explicitly return 0 if it's automatically done by the compiler?
3
votes
9 Answers
10
votes
14
votes
4
votes
4
votes
4
votes
3
votes
0
votes
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.
return 0;
on principle unless non-zero is a valid return value. It makes me feel like a rebel. – Dennis Zickefoose