I have a question regarding how and in which order if() checks multiple conditions. I would like to call functions directly in the if statement. In an if statement like this:
if (condition1 || function1)
return SOMETHING;
The first part of the logical expression will be checked, so if condition1 == 1. If this proved to be true, the whole statement is true, therefore the function function1 will not be executed, am I right?
What happens with something like this:
if (!(condition1 && function1))
return FAIL;
Will the compiler turn this into:
if (!condition1 || !function1)
return FAIL;
And not execute function1 if !condition1 turns out to be true? Or will it first check condition1 and execute function1 because of the AND operator and than negate the result? What if I switch the order?
Aucun commentaire:
Enregistrer un commentaire