Learn to combine multiple conditions using logical AND (`&&`), OR (`||`), and NOT (`!`).
Logical operators are used in C to combine or invert the results of relational expressions, allowing for more complex decision-making. While relational operators compare single values, logical operators work with the boolean outcomes (true/1 or false/0) of those comparisons. There are three logical operators: AND (`&&`), OR (`||`), and NOT (`!`). The logical AND (`&&`) operator evaluates to true (1) only if both of its operands are true. If either operand is false, the result is false. For example, the expression `(x > 5) && (y < 10)` is true only if `x` is greater than 5 AND `y` is less than 10. C also uses short-circuit evaluation for `&&`; if the first operand is false, the second operand is not evaluated at all, because the overall result must be false. The logical OR (`||`) operator evaluates to true (1) if at least one of its operands is true. It is false only when both operands are false. For example, `(country == 'USA') || (country == 'CAN')` is true if the country is either 'USA' OR 'CAN'. Similar to AND, OR also uses short-circuiting; if the first operand is true, the second is not evaluated because the overall result is already known to be true. The logical NOT (`!`) operator is a unary operator that inverts the boolean value of its operand. If an expression is true, `!expression` is false, and vice versa. For example, `!(x == 5)` is the same as `x != 5`. These operators are essential for building sophisticated conditional logic in your programs.