lundi 25 novembre 2019

In which order is && and || is evaluated in C?

if (2<3 || 3<4 && 5>6) printf("OK");
else printf("FAIL");

I am confused on how will the computer evaluate this if statement. My guess is (Since && comes before ||):

if ((2<3 || 3<4) && 5>6) printf("OK");
else printf("FAIL");

Since the statement is wrong the if should print FAIL. But the answer sheet says that the answer is OK. My question is that when encountered with a situation like this should i evaluate from left to right or start from &&?

Aucun commentaire:

Enregistrer un commentaire