Thread: exit(); and exit(0);

  1. #1
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385

    exit(); and exit(0);

    if i use exit(); in my code it throws and undefined function erro f i pass any int value as aparameter to it it excepts it

    ie exit() fais to work

    exit(0), exit(1) exit(998) all work

    what is the significance of the parameter? and why is it needed/
    Monday - what a way to spend a seventh of your life

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    That is the value that gets returned to the operating system.
    at the end of main you have return 0, but if you use the exit function, you skip that return statement, but you need to return a value because the os is expecting one.
    What ever you pass to exit will be returned to the os.

  3. #3
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    when i use return and exit(x), they return values - i undersatnd that the ones to use are 1 and 0 indicating error and success respectivly. So how does the os (windows in my case) respond. I have never seen it take action as a result of adjusting the return value.
    Monday - what a way to spend a seventh of your life

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    it may be in the transparent disposal of the programs used resources, im not sure.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    maybe its because this is c++ and the function is prototyped like this.....

    void exit(int);

    therefore a call to exit() will result in a function not found error.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Chat Program Help?
    By Paul22000 in forum Networking/Device Communication
    Replies: 9
    Last Post: 02-10-2009, 12:35 AM
  2. exit() vs return()
    By kryptkat in forum C Programming
    Replies: 9
    Last Post: 10-21-2006, 11:26 AM
  3. fork(), exit() - few questions!
    By s3t3c in forum C Programming
    Replies: 10
    Last Post: 11-30-2004, 06:58 AM
  4. Couple of Q's.....
    By oobootsy1 in forum C++ Programming
    Replies: 18
    Last Post: 02-23-2004, 02:03 PM
  5. Exit a function
    By MasterGBC in forum C Programming
    Replies: 3
    Last Post: 04-10-2003, 10:46 PM