What is difference between return 1 and return 0 | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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

26th Feb 2020, 12:48 PM
Jahnvi Pandey
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)
26th Feb 2020, 12:53 PM
Utkarsh Sharma
Utkarsh Sharma - avatar
+ 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
26th Feb 2020, 1:07 PM
Jayakrishna 🇮🇳
0
In JavaScript : return 0; // false return 1; // true
26th Feb 2020, 1:45 PM
JS LOVER
JS LOVER - avatar