Can I omit return from main in C?
Yes, as of C99, reaching the }
at the end of main returns 0 if the return type of main
is compatible with int
.
5.1.2.2.3 Program termination
If the return type of the
main
function is a type compatible with int, a return from the initial call to themain
function is equivalent to calling theexit
function with the value returned by themain
function as its argument;11) reaching the}
that terminates themain
function returns a value of 0. If the return type is not compatible withint
, the termination status returned to the host environment is unspecified.
Yes, the C99 standard says (§5.1.2.2.3):
reaching the
}
that terminates themain
function returns a value of 0.