954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Exit()

What's the differences between exit(0), exit(1) and exit(-1)?

dhruv_arora
Junior Poster
127 posts since Jun 2010
Reputation Points: 15
Solved Threads: 4
 

The paramarater is the value that the program will return to the operating system so that other programs can use it for some purpose. The value 0 traditionally means the program exits normally without error. Any other value would mean the program encountered some kind of error. The value of the parameter to exit() can be anything you want, its not limited to the three that you posted.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Exit(0) , is commonly used as a successful exit message. Usually, you don't use it, use instead Return 0; Exit(1) Is used to reference some kind of abnormal program termination.

Nichito
Posting Virtuoso
1,602 posts since Mar 2007
Reputation Points: 424
Solved Threads: 57
 

>>Usually, you don't use it, use instead Return 0;

Unless, of course, exit() is used outside main().

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Point granted ;)

Nichito
Posting Virtuoso
1,602 posts since Mar 2007
Reputation Points: 424
Solved Threads: 57
 

Thanks for the info.

dhruv_arora
Junior Poster
127 posts since Jun 2010
Reputation Points: 15
Solved Threads: 4
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You