Returning a value from the main()
function is equivalent to calling exit()
with that value. So your code is similar to:
int main() {
std::exit(0);
}
The exit status is returned to the runtime library. It can be accessed by the parent process that invoked the program; on Unix this is done using the wait()
family of calls. If you run the program from a Unix shell, the exit status is put in the variable $?
, or you can test it using control statements like if
or while
.