What’s the difference? Which is preferred, or when should I use each one respectively?
What’s the difference? Which is preferred, or when should I use each one respectively?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
exit(1)(usually) indicates unsuccessful termination. However, its usage is non-portable. For example, on OpenVMS,exit(1)actually indicates success.Only
EXIT_FAILUREis the standard value for returning unsuccessful termination, but1is used for the same in many implementations.So to summarize:
If you want to write perfectly portable code use,
EXIT_FAILUREfor failure case. While,You can use either
exit(0)orEXIT_SUCCESSfor success case.Note that,
EXIT_SUCCESSor0are both same.Reference:
C99 Standard: 7.20.4.3 The
exitfunctionPara 5