how do you exit from inside a function?:confused:
Printable View
how do you exit from inside a function?:confused:
The easy way is to "return". Be carefull here as the return value is dependant on your function declaration.
Is that what you wanted?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
}
Oh... you can use exit(0) too, to finish the program at any time.....