Search code examples
c++binary-operators

C++ Binary operators order of precedence


In what order are the following parameters tested (in C++)?

if (a || b && c)
{
}

I've just seen this code in our application and I hate it. I want to add some brackets to just clarify the ordering. But I don't want to add the brackets until I know I'm adding them in the right place.

C++ built-in operators, precedence, and associativity has more information, but it's not totally clear what it means. It seems || and && are the same precedence, and in that case, they are evaluated left-to-right.


Solution

  • From here:

    a || (b && c)
    

    This is the default precedence.