exiting

This is a discussion on exiting within the C++ Programming forums, part of the General Programming Boards category; how do you exit from inside a function?...

  1. #1
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87

    exiting

    how do you exit from inside a function?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    The easy way is to "return". Be carefull here as the return value is dependant on your function declaration.

    Code:
    int foobar(int& x){
    while(x < 500){
    x++;
    
    
    }
    return x; //go back to main
    }
    
    int main(void){
    int x = 0;
    foobar(x);
    cout << x << endl;
    return 0; //return 0 to Operating System
    }
    Is that what you wanted?

    Oh... you can use exit(0) too, to finish the program at any time.....
    Last edited by Fordy; 11-22-2001 at 02:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple crash problem (exiting func)
    By te5la in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2008, 04:15 PM
  2. Exiting the program.
    By Taka in forum C Programming
    Replies: 6
    Last Post: 10-14-2007, 10:24 AM
  3. Exiting windows through a C program.
    By Afro in forum C Programming
    Replies: 3
    Last Post: 06-23-2007, 09:29 AM
  4. Ask user to save file before exiting.
    By Bajanine in forum Windows Programming
    Replies: 3
    Last Post: 11-15-2004, 06:34 PM
  5. prevent exiting
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-12-2001, 02:57 PM

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