0

Difference b/w return 1 , return 0 and return -1 ?????

22nd Jan 2017, 5:42 AM
Ankish Gupta
Ankish Gupta - avatar
3 Antworten
+ 3
Return 0 means that your program executed without errors and you don't have to return it explicitly, because that'll happen automatically when main terminates. Return 1 means that your program had an error.
22nd Jan 2017, 6:54 AM
mohammad Shojaeinia
mohammad Shojaeinia - avatar
+ 2
No difference at all. but we generally write return 0 to tell the is that there was no error or the program ran successfully. you can write return 123,return 375, return anything.
22nd Jan 2017, 5:51 AM
Megatron
Megatron - avatar
+ 1
These are different values which your function returns. It is your decision which values your functions return and how other functions react on these returned values. You can use it as error codes, if you don't want or cannot use exceptions. Also Java doesn't have a requirement that every function must return something.
22nd Jan 2017, 5:54 AM
Ivan G
Ivan G - avatar