0

What is the diffrence between using "return 0" and "return 1"

9th Jul 2016, 2:44 PM
Vaasu Bhatnagar
Vaasu Bhatnagar - avatar
3 Respostas
+ 1
If you want to return that the program has executed correctly, you return 0. If something hasn't executed the way it was supposed to, you return any other number than 0. It can be 1 or it can be -836. Doesn't matter, as long as it's not 0. In that way, you can see where the program returned a number that's not 0, see why it did it and then correct the problem that occurred.
9th Jul 2016, 3:31 PM
Asad
+ 1
In a function it depends on the purpose. In main function ending with "return 0" assigns 0 to system variable ERROR_LEVEL which means it terminated with no error.
9th Jul 2016, 3:32 PM
Albert Gullbee
0
Whatever you return from main typically gets fed back to whatever launched the program. A return value of zero indicates the program ran successfully, whereas nonzero indicates a failure of some kind. For stand-alone programs it doesn't really matter all that much, as this code is often ignored. But for launching programs inside batch scripts, where multiple programs need to run in succession... an error code could halt the entire script.
9th Jul 2016, 6:20 PM
imnoob
imnoob - avatar