I'm learning C++ and java and I've noticed how if you have a conditional, whatever code follows will be executed if the condition is true, even if you don't explicitly write == true
Consider the following very simple C++ code:
bool c_plus_plus_is_cool(){
return true;
}
int main(){
if (c_plus_plus_is_cool()) {
cout << "C++ is cool!";
}
return 0;
}
Q: What is the difference between
if (c_plus_plus_is_cool())
and if (c_plus_plus_is_cool() == true)
?
And is this also the case in other languages (like Java (where I've been writing ==true
all this time...)) ?