[try Beta version]
Not logged in

 
return 0; what?

Jul 8, 2010 at 6:12am
I've heard so many different explanations of what return 0; is that i don't even know anymore. So what is it?
Jul 8, 2010 at 6:13am
Jul 8, 2010 at 6:19am
Ha ha very funny. I mean the line of code.
Jul 8, 2010 at 7:26am
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)
Jul 9, 2010 at 11:41am
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.
Jul 9, 2010 at 4:50pm
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.
Jul 9, 2010 at 5:07pm
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
Jul 13, 2010 at 6:23pm
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.