You are here:

C/exit(0) & exit(1)

Advertisement


Question
Sir,
Can you please explain the difference between exit(0) and exit(1)with one example.
Both will terminate a program.
But I want to know whether there is any difference between them or not.
Tell me some situations where we have to use exit(1) instead of exit(1).
Thanks in Advance.

Answer
Hello Murali

You are correct that both versions of exit terminate the program. The exit(0) or exit(EXIT_SUCCESS) is used to show that a program ran successfully. The exit(1) or exit(EXIT_FAILURE) is used to show that a program failed in some way.

You can get the exit code from the operating system shell. For the Microsoft operating systems, if you started the program from a command line, you can get the exit code by examining the ERRORLEVEL variable. For UNIX/Linux, you can get the exit code by examining the $? variable.

Best regards

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Zlatko

Expertise

No longer taking questions.

Experience

No longer taking questions.

Education/Credentials
No longer taking questions.

©2012 About.com, a part of The New York Times Company. All rights reserved.