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
It makes behavior of the code explicit.
By being explicit you are explicitly showing your intent.
By relying on something implicit you could have 2 cases: 1) You intended it, 2) You forgot it.
Because this is how they did it 30 years ago. It is more of a convention IMO.
Because it just looks weird to not "return" something from a function having a non-void return type (even if the standard says it's not strictly necessary).
Makes it clear to other programmers that you didn't just forget to put the return statement there.
Some compilers may issue a warning if you don't return anything.
Shows explicitly what the function returns.
Many programmers don't know about this rule.
Misunderstanding. There's simply no reason to, and if someone doesn't know that they'll add return 0;
.