The return result from main is used to tell the environment whether the program was successful (or not).
Code:
$ cat foo.c && gcc foo.c && ./a.out ; echo "Process exit status = " $?
#include<stdio.h>
int main( void ) {
return 0;
}
Process exit status = 0
$ cat foo.c && gcc foo.c && ./a.out ; echo "Process exit status = " $?
#include<stdio.h>
int main( void ) {
return 1;
}
Process exit status = 1
0 always means success, as does the constant EXIT_SUCCESS. EXIT_FAILURE denotes a failure, and any other numeric constant is dependent on your OS / environment.
Use ERRORLEVEL in DOS command.com / Win32 cmd.exe