On Unix and Linux systems, the value returned to the shell by a C program is either
- 256+the signal number if the program terminated due to a signal
- the lowest 8 bits of the value passed to a call to
exit
or _exit
- the lowest 8 bits of the value in a
return
statement in main
- if compiled with a C99-standard compiler and
main
is declared to return a value compatible with int, then falling off the end of main
will result in an exit value of 0.
- undefined behavior
In your case, it was undefined behavior. It looks like the return value from printf
was 11, because that's the number of characters that were written. Since there were no intervening function calls between the call to printf
and the end of main
, this value remained in the register where function return values are stored.
You can't rely on this behavior. It will vary depending on the compiler, runtime library, and operating system. It is best to call exit
or to use a return
statement in main
with a value.
There are some conventions for exit code values. See Are there any standard exit status codes in Linux.