Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The || (logical OR) operator is a binary operator that performs a boolean inclusive disjunction on two scalar operands. It evaluates to 1 (of type int) if at least one of its operands compares unequal to 0, and evaluates to 0 if both operands compare equal to 0.
logical-OR-expression:
    logical-AND-expression
    logical-OR-expression || logical-AND-expression

Operand Requirements

Both operands must be of scalar types, which include arithmetic types (integer and floating-point) and pointer types. The operands are not required to be of the same type. During evaluation, each operand is implicitly compared against 0 (or a null pointer).

Evaluation Mechanics and Short-Circuiting

The || operator enforces strict left-to-right evaluation and implements short-circuit evaluation.
  1. The left operand is evaluated first.
  2. If the left operand evaluates to a non-zero value (true), the overall expression is guaranteed to be true. Consequently, the right operand is not evaluated.
  3. The right operand is evaluated if and only if the left operand evaluates to 0 (false).
// Syntax visualization of short-circuiting
(expr1) || (expr2)
If expr1 != 0, expr2 is completely ignored, including any function calls or side effects within it.

Sequence Points

A sequence point exists immediately after the evaluation of the first operand. All side effects of the first operand (such as post-incrementing or memory writes) are guaranteed to be complete before the second operand is evaluated (if it is evaluated at all).

Result Type

Regardless of the types of the operands provided, the result of the || operator is always of type int. The resulting value is strictly normalized to either 1 or 0.

Precedence and Associativity

  • Precedence: The || operator has lower precedence than the logical AND operator (&&) and higher precedence than the conditional operator (?:) and all assignment operators.
  • Associativity: It groups left-to-right. An expression like a || b || c is parsed as (a || b) || c.
Master C with Deep Grasping Methodology!Learn More