In C++, 3.6.1 Main function
(3.6.1/5) A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing return 0;
Can I do the following in C99 without return 0?
int main() { }
In a main function, the return statement and expression are optional.
The C++ standard explicitly says "It [the main function] shall have a return type of type int , but otherwise its type is implementation defined", and requires the same two signatures as the C standard to be supported as options.
Short Answer: Nothing. Better Answer: return 0 it's used in main like a signal for know the exit of program was a success when return 0 executes. Best Answer: Still nothing because compilers already "put" return 0 in the the end of your code if you not explicit.
As the user-defined function declaration mandates return 0, so we must utilize return 0, or return -1 within each C program. If we wouldn't directly declare a value, the assembler automatically includes a return 0; so it is optional to insert a return 0.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With