0
Why do we put return 0?what does it do?
5 Réponses
+ 1
Adding return 0 ensures that nothing else returns it basiclly cleans up the code so we dont get a wierd output
+ 1
Return 0 from main is the return value used to indicate that the program ran successfuly without any errors. We return an integer because main has a return type of int, and just like any other function, something must be returned.
Other return values from main (such as 1), indicate the program did not finish with the expected outcome, so there was an error of some sorts.
0
what if we put return 1 or 2 what output we may get
0
it's pretty standard practice in Unix to check for non zero exit status of executable and use it to resolve issues
- 1
0 means empty, so you return nothing, which in turn tells the program to stop or simply do nothing. if you put something other than 0, it means you return something that is not empty and has more value, so the program will keep running as it must do something aside from nothing which may lead to error if not handled properly