+ 1

why return0 to terminate a program, why not return5

18th Oct 2016, 2:44 PM
Giridhar V B
7 ответов
+ 3
if you created a function of integer type then you can return any value but "it should be in integer type " so if you want to return 5 then you do so, ->because function "int main() " or any "int abc()" tells you to return a integer not tells you to return 0 only. example :-int main(){ int a=1,b=4; return a+b; } here you not have to return 0 because function already return an integer value, which is a+b
18th Oct 2016, 5:43 PM
Chetan kumar das
Chetan kumar das - avatar
+ 2
because in programming, 0 means successful execution
18th Oct 2016, 7:13 PM
Ankur
Ankur - avatar
0
Remember your code is called by the operating system. Former OS where textual only and by default if a program returned 0 it meant it worked OK, it failed otherwise, usually each number indicating a different error.
18th Oct 2016, 3:27 PM
Silvano Mignanti
Silvano Mignanti - avatar
0
it haven't different you can return any number but if you have a function you can return the result of your function. for example: int sum (int,int); int main(void) { a=2; b=3; c=sum(a,b); cout<<c; } int sum (int a,int b) { return a+b; } /////////////////^ result: 5
22nd Oct 2016, 3:57 PM
ehsan
0
0 is a standard exit code for successful execution, that's exactly how I check my Runtime.exec() calls in Android for success execution.
22nd Oct 2016, 5:47 PM
MSF Jarvis
MSF Jarvis - avatar
- 2
there is no diffrence. you can use return 5
18th Oct 2016, 3:26 PM
Michal Kalinowski
Michal Kalinowski - avatar
- 3
bcz return 0 returns the value of program with 0 and after termination the program will start from beginning
18th Oct 2016, 3:26 PM
Hardik Jain
Hardik Jain - avatar