On POSIX systems (like macOS or Linux) the return-code from a process is made up of several parts, and the return-code from main
is only stored in the low eight bits of the int
value.
Most modern systems uses two's complement to represent negative integers, and with that the signed value -1
becomes 255
because all bits in the byte will be set.
Because of this it's not recommended that you return negative numbers from main
(or call exit
with a negative number). Instead use only small non-negative numbers, where 0
is considered success. Or of course use the standard EXIT_SUCCESS
and EXIT_FAILURE
macros.
Windows, not being a POSIX systems, doesn't really care about this, and uses the whole int
value for the returned value.