main
must return an int
, some compilers, including Turbo C++, may allow other return values, notably void main
, but it's wrong, never use that.
However in C++, if you don't explicitly return a value in main
, it's the same as return 0;
C++11 §3.6.1 Main function section 5
A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling std::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;
Note that for C, this is only supported in C99 and later, but not supported by C89.