Closed antoniocaruso closed 5 months ago
From what I can tell, the absence of the return in main() was a deliberate decision on the part of the author. The reason and rationale is referenced in the section 28.1.1.
28.1.1 Returning From main()
If you’ve noticed, main() has a return type of int… and yet I’ve rarely, if ever, been returning anything from main() at all.
This is because for main() only (and I can’t stress enough this special case only applies to main() and no other functions anywhere) has an implicit return 0 if you fall off the end.
You can explicitly return from main() any time you want, and some programmers feel it’s more Right to always have a return at the end of main(). But if you leave it off, C will put one there for you.
So… here are the return rules for main():
You can return an exit status from main() with a return statement. main() is the only function with this special behavior. Using return in any other function just returns from that function to the caller.
If you don’t explicitly return and just fall off the end of main(), it’s just as if you’d returned 0 or EXIT_SUCCESS.
Yes, it was deliberate.
Hello world, first example. If you define the main to return an integer, is not really nice to have a function without a return. This is a problem in all code examples.