0
What is the diffrence between using "return 0" and "return 1"
3 Réponses
+ 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.
+ 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.
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.