C++ Code Example: if else statement on boolean expressions

Logical operators have different priorities and therefore are executed at different times.

The order is as follows:
Logical complements (!) are executed first,
logical conjunctions (&&) are executed next,
and logical disjunctions (||) are executed at the end.

Code Example

In this case, a and b are both true, while c is false. Therefore, the expression (a or b) evaluates to true (since at least one of a and b is true), but the expression (a or b) and c evaluates to false (since c is false).

#include <iostream>
using namespace std;

int main() {
    bool a = true, b = true, c = false;

    if ((a or b) and c) {
        cout << "True";
    } else {
        cout << "False";
    }

    return 0;
}
Output
False