mardi 7 septembre 2021

How does the compiler evaluates expression with multilple comparison operators inside of the if-statement? [duplicate]

So I have this program that returns "result: true"

if (true == false != true) {
    cout << "result: true";
}
else {
    cout << "result: false";
}

even if we flip the comparison operators inside of the if-statement, the compiler still evaluates the expression to be true

if (true != false == true)

My question is:

  1. How does the compiler actually evaluates the expression?
  2. and to which comparison operator out of the two present inside of the if-statement, preference is given?

Aucun commentaire:

Enregistrer un commentaire