As a return sequence you usually use return 0. In other codes I've seen return 1, and return -1. What does return 1 do? Please explain it to me. I've looked in the FAQ but it had no reference on return values.
As a return sequence you usually use return 0. In other codes I've seen return 1, and return -1. What does return 1 do? Please explain it to me. I've looked in the FAQ but it had no reference on return values.
Child who knows C++Using Borland C/C++ Compiler 5.5 (Command Line Version)
Yes! finally something I can help with. anyways, return values are up to the programmer to decide what to do with. If you called a function from within another function, you could check the return value. This can be very useful in a lot of situations. You would be able to do something like this:
I might have misunderstood your question though, if you meant why someone would return something other than 0 from main, I am not sure about that.Code:int Add(int number1, int number2) { return (number1+number2); } int main() { cout<<Add(1, 2); return 0; }
"Computers aren't intelligent, they only think they are."
**infected by Blizzarddog**
I am a signature virus. Please add me to your signature so that I may multiply
When dealing with main, a return value of 0, by convention means success (to any external programs/users watching to see if the program successfully ran). Any other value (again, by convention) indicates failure. Different programs may return different values for different types of failures.
Why would you want to return an error?
Perhaps your program failed to achieve its goal. It can be useful for the user to know why the program failed. For example, say you have an engineering analysis program of some sort. If your program fails to perform the analysis, it is helpful to know why (perhaps the input data was invalid).
Ahh, ok thanks.