0

Why do we put return 0?what does it do?

6th Nov 2016, 6:56 PM
Bomte Gapak
Bomte Gapak - avatar
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
6th Nov 2016, 6:58 PM
aryav
aryav - avatar
+ 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.
6th Nov 2016, 7:05 PM
Cohen Creber
Cohen Creber - avatar
0
what if we put return 1 or 2 what output we may get
6th Nov 2016, 7:03 PM
Bomte Gapak
Bomte Gapak - avatar
0
it's pretty standard practice in Unix to check for non zero exit status of executable and use it to resolve issues
6th Nov 2016, 8:53 PM
Robert McC
Robert McC - avatar
- 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
6th Nov 2016, 10:05 PM
abam 96
abam 96 - avatar