Coding Ref

exit(0) and exit(1) in C

exit(0) and exit(1) in C

exit(0) indicates a successful program termination and it is fully portable. exit(1) usually indicates an unsuccessful termination and it is non-portable.

exitTerminationPortable
exit(0)SuccessfulPortable
exit(1)UnsuccesfulNon-portable

The C standard defines EXIT_SUCCESS and EXIT_FAILURE to return termination status from a C program.

0 and EXIT_SUCCESS are the values specified by the standard to indicate successful termination, however, only EXIT_FAILURE is the standard value for returning unsucessful termination. 1 is used for the same in many implementations though.

Is it okay to use exit(1) to abort the program or should you return 1 from the main()?

This is a choice for you to make yourself.

If you're writing a library, you ought to report failure to the caller, which may be able to recover in ways you can't internally, and which might need to perform other cleanup that's not done by registered atexit() handlers.

It is generally recommended returning from main(). Some use of exit() in code that will not be in a library is acceptable.

Conclusion

exit(0) indicates a successful program termination and it is fully portable. exit(1) usually indicates an unsuccessful termination and it is non-portable.