return 0; what?

I've heard so many different explanations of what return 0; is that i don't even know anymore. So what is it?
Ha ha very funny. I mean the line of code.
It returns 0.

That's the answer you'd get if I ignored the fact that this should go in http://www.cplusplus.com/forum/beginner/ and just felt like messing around.
This is the real answer:

"To return an expression" means " to transfer control back to the caller and evaluate the call to the value of the expression (after evaluating it, obviously)".
http://en.wikipedia.org/wiki/Return_statement
http://en.wikipedia.org/wiki/Control_flow
http://en.wikipedia.org/wiki/Expression_%28programming%29 (expression evaluation)
It's basically telling your program that it executed fine...

return 1; would tell your program that it encountered an error.

So use return 0; (or return EXIT_SUCCESS; ) when you want to end the program and you're sure that no error has come up.
return 1; would tell your program that it encountered an error.
No. That tells the shell that the program failed. Maybe. The shell is free to ignore it.
Isn't the point of returning values in main() mostly used by shell scripts?

For example:
1
2
3
4
5
6
7
do_something_important $DSIARGS

if [[ $? -neq 0 ]]; then
        echo "Failure" >&2
else
        echo "Success"
fi
Return value (the exit code) should be taken into account by any application calling another application. The term "Application" here may refer to a shell script, regular application, daemon, etc.
Topic archived. No new replies allowed.