Operator Precedence, Associativity & Short-Circuit Evaluation
“Unary, Ternary, and Assignment operators associate Right-to-Left; logical && and || short-circuit evaluation from left to right, bypassing right operands when outcome is determined.”
- —Precedence order: Postfix > Unary (R-to-L) > Multiplicative > Additive > Shift > Relational > Equality > Bitwise > Logical > Ternary (R-to-L) > Assignment (R-to-L) > Comma.
- —expr1 && expr2: If expr1 is 0, expr2 is NOT evaluated.
- —expr1 || expr2: If expr1 is non-zero, expr2 is NOT evaluated.
- —*p++ evaluates as *(p++): dereferences old p, then increments pointer.
- —(*p)++ dereferences p and increments the target integer value.
- —Do not assume bitwise & has higher precedence than equality ==; relational and equality operators have HIGHER precedence than bitwise operators in C!