0
What is difference between return 1 and return 0
When i used return 0 i get the same input as when i used return 1
3 Réponses
+ 2
For C family (C/C++ etc) you can refer to Jayakrishna 's answer.
In Python what I have observed--
The function is ended after return, it does not matter what you return, but the value of function changes... For example--
def f():
return 1
#The function will end here
print(f())
It will print 1
def f():
return 0
# The function will end here
print(f())
It will print 0
You can use this in conditions to return either true, false or any value you want but the function will always stop after return. It doesn't affect input but it can be affected by it
If f() == 1:
print(True)
else:
print(False)
+ 1
In c, from the main function, if it returns 0, that means Program completed successfully, and if it returns, any other nonzero value then it means, program is unsuccessful, exited with an error..
Since in your program, return statement is last statement so it doesnot effect Program..
It just exit status of a program telling to the operating system.
Edit:
Pls tag the language also.
For more info see these...
https://www.includehelp.com/c/return-0-from-int-main-in-c-programming.aspx
https://www.quora.com/What-is-the-difference-between-return-1-and-return-0-in-C
0
In JavaScript :
return 0; // false
return 1; // true