Return. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Return.

What is the different between ' Return 0 ' , ' Return 1 ' and ' Return TRUE'

31st Jan 2017, 12:01 PM
AmierAiman 47
AmierAiman 47 - avatar
8 Answers
+ 2
If the function is of type bool the return value must have this type. This can be true or false. An example: This test is an int is even or uneven. bool isEven(const int n){ if(n%2){ return true; } else{ return false; } } The main function must not have type bool. It hast always type int!
31st Jan 2017, 12:20 PM
~datell
+ 1
return is used to let a function or method returning a value. Depending in the function this value has a different type. If your function is of type int it must return ints (int main() is such a function but main must not return anything anymore). If yohr function is of type bool it must return a bool (return TRUE for example).
31st Jan 2017, 12:04 PM
~datell
+ 1
The return 0/1 thing for showing an error is jus a convention. It has nothing to do with the language itself. Programmers use to let main return 0 if everything went good and 1 if an error occured. But as I said this is a convention and not a language feature.
31st Jan 2017, 12:08 PM
~datell
0
Thanks so much!
31st Jan 2017, 12:06 PM
AmierAiman 47
AmierAiman 47 - avatar
0
So when the main function is bool the ending mist be ' Return TRUE '
31st Jan 2017, 12:11 PM
AmierAiman 47
AmierAiman 47 - avatar
0
Is it?
31st Jan 2017, 12:13 PM
AmierAiman 47
AmierAiman 47 - avatar
0
Sorry but the ' return false ' still dont understand. Guess i need to continue learning.
31st Jan 2017, 12:25 PM
AmierAiman 47
AmierAiman 47 - avatar
- 3
return 0 means you tell the program to interrupt without showing any error, as the programm stopped due to an error, but return 1 is the opposite, it means stop the programm and tell the User that it was a problem somewhere.
31st Jan 2017, 12:05 PM
Oussama Jaaouani
Oussama Jaaouani - avatar