Usually, when the program executes "as expected", we return 0. If it does something, it should not, we return a nonzero value depending on the type of error (for this you can refer to the errno manual). Now this return value is received by the "shell" under which the program was launched. This return value can be obtained using "$?" in BASH. Thus, it is purely for the user accessibility for the program (that it works correctly, and if not, then what error). This return value can then be used in shell scripts, etc., to make decisions about whether to repeat or what to do, what the administrator wants to do. The kernel simply clears the user land program.
source share