Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clarifying Return 0 and 1

Tags:

c++

c

return

So returning 0 in a function (Not main) means false and returning 1 or anything but 0 means success.

Why in the main() function do we put 0, meaning there were no errors when 1 in other functions mean it ran successfully, thanks.

like image 624
user2756669 Avatar asked Sep 07 '13 09:09

user2756669


People also ask

What does return 0 and return 1 means?

return 0: A return 0 means that the program will execute successfully and did what it was intended to do. return 1: A return 1 means that there is some error while executing the program, and it is not performing what it was intended to do.

What is use of return 1 in C?

in main function return 0 or exit(0) are same but if you write exit(0) in different function then you program will exit from that position. returning different values like return 1 or return -1 means that program is returning error .

What does return 1 do in Java?

Your method has no return type, Provide a return type of int in your method. And return -1 means nothing in java, you are just returning a int value, thats it.

What is a 0 return?

Answer. You had no tax liability for the prior year if your total tax was zero or you didn't have to file an income tax return. Your total tax was zero if the line labeled "total tax" on Form 1040, U.S. Individual Income Tax Return or Form 1040-SR, U.S Tax Return for Seniors was zero.


1 Answers

0 and 1 (or any non-zero number) convert to the boolean values false and true in a context where a conversion to bool happens, e.g. in if(here) .... This is used within your program.

The return value from main is used in a different way, it is returned to the shell that called the program. In the shell's context the value is interpreted differently. There, 0 traditionally means "no error" while values larger than zero indicate errors and the value itself contains some hints as to what kind of error occurred. Take this snippet from man grep:

EXIT STATUS
     The grep utility exits with one of the following values:

     0     One or more lines were selected.
     1     No lines were selected.
     >1    An error occurred.
like image 53
Daniel Frey Avatar answered Oct 23 '22 18:10

Daniel Frey