New course! Every coder should learn Generative AI!
Try a free lesson0
Return.
What is the different between ' Return 0 ' , ' Return 1 ' and ' Return TRUE'
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!
+ 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).
+ 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.
0
Thanks so much!
0
So when the main function is bool the ending mist be ' Return TRUE '
0
Is it?
0
Sorry but the ' return false ' still dont understand. Guess i need to continue learning.
- 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.