Thread: Explain exit()

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    18

    Question Explain exit()

    Can anyone explain to me the use of exit() ? What is the difference of exit(1) and exit(0)? I would be really grateful if someone could explain me about it..

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by cloudpuffballz View Post
    Can anyone explain to me the use of exit() ? What is the difference of exit(1) and exit(0)? I would be really grateful if someone could explain me about it..
    1 means something and 0 means something too....in main you return 0 to say that everything is ok,you return -1 to say not ok...so something like that comes to mind...google it and sure you find an answer.If not post back

    EDIT->Actually the indian geek just did it :-p

  4. #4
    Registered User
    Join Date
    Jul 2012
    Posts
    18
    Thank you!

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Quote Originally Posted by std10093 View Post
    1 means something and 0 means something too....in main you return 0 to say that everything is ok,you return -1 to say not ok...so something like that comes to mind...google it and sure you find an answer.If not post back

    EDIT->Actually the indian geek just did it :-p
    On error you return positive values, not negative. And I believe 1 is the only "official" error return.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  6. #6
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by WaltP View Post
    On error you return positive values, not negative. And I believe 1 is the only "official" error return.
    Good point

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by WaltP
    On error you return positive values, not negative. And I believe 1 is the only "official" error return.
    The C standard only mandates that 0 and EXIT_SUCCESS from <stdlib.h> denote successful termination and that EXIT_FAILURE denotes unsuccessful termination. The values of EXIT_SUCCESS and EXIT_FAILURE are unspecified, though it is clear that EXIT_FAILURE must be non-zero.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Quote Originally Posted by laserlight View Post
    The C standard only mandates that 0 and EXIT_SUCCESS from <stdlib.h> denote successful termination and that EXIT_FAILURE denotes unsuccessful termination. The values of EXIT_SUCCESS and EXIT_FAILURE are unspecified, though it is clear that EXIT_FAILURE must be non-zero.
    Another good point...
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The C standard does not stipulate that only EXIT_SUCCESS and EXIT_FAILURE must be passed to exit(). It only specifies what those two values mean. Other values may be returned but the standard specifies no meaning for them. That is why some programs are able to return values that can be used (say) by a shell script or similar.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to never exit
    By newcguy in forum C Programming
    Replies: 13
    Last Post: 12-16-2006, 12:14 PM
  2. exit(-3)
    By Moony in forum C Programming
    Replies: 6
    Last Post: 07-06-2006, 12:47 PM
  3. exit() ?
    By smd in forum C++ Programming
    Replies: 4
    Last Post: 06-26-2002, 04:31 PM
  4. exit(); and exit(0);
    By iain in forum C++ Programming
    Replies: 4
    Last Post: 01-17-2002, 08:37 PM
  5. exit
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 01-03-2002, 03:10 PM

Tags for this Thread