Like Tree1Likes
  • 1 Post By manasij7479

Explain exit()

This is a discussion on Explain exit() within the C Programming forums, part of the General Programming Boards category; Can anyone explain to me the use of exit() ? What is the difference of exit(1) and exit(0) ? I ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    rags_to_riches likes this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    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,157
    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,675
    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
    21,456
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,157
    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,208
    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%.

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, 11:14 AM
  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, 07:37 PM
  5. exit
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 01-03-2002, 02:10 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21