> ## 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.

# C++ Logical OR

The `||` (Logical OR) operator is a binary operator in C++ that performs a logical disjunction on two expressions. It yields a prvalue of type `bool`, returning `true` if at least one of its operands evaluates to `true`, and `false` strictly when both operands evaluate to `false`.

```cpp theme={"dark"}
expression1 || expression2
```

## Operand Conversion

Before the operation is performed, both `expression1` and `expression2` are contextually converted to `bool`. For arithmetic and pointer types, any non-zero value or non-null pointer evaluates to `true`, while zero or null evaluates to `false`.

## Short-Circuit Evaluation

The `||` operator enforces strict left-to-right evaluation and utilizes short-circuiting.

1. `expression1` (the left operand) is evaluated first.
2. If `expression1` evaluates to `true`, the overall expression is guaranteed to be `true`. Consequently, `expression2` (the right operand) is **not evaluated at all**.
3. If `expression1` evaluates to `false`, `expression2` is evaluated to determine the final result.

There is a strict sequence point (or sequenced-before relationship in modern C++) after the evaluation of the left operand and before the evaluation of the right operand. All side effects of the left expression are guaranteed to be committed before the right expression is evaluated.

## Precedence and Associativity

* **Associativity:** Left-to-right. An expression like `a || b || c` is parsed as `(a || b) || c`.
* **Precedence:** The `||` operator has lower precedence than the Logical AND operator (`&&`), equality operators (`==`, `!=`), and relational operators (`<`, `>`), but higher precedence than assignment operators (`=`, `+=`) and the ternary conditional operator (`?:`).

## Alternative Token

C++ provides the alternative spelling `or` defined in the standard. It is a primary token and behaves identically to `||` at the compiler level.

```cpp theme={"dark"}
expression1 or expression2
```

## Operator Overloading

The `||` operator can be overloaded for user-defined types by defining `operator||`. However, doing so fundamentally alters the operator's evaluation semantics:

* **Loss of Short-Circuiting:** When overloaded, the operator behaves as a standard function call. Both operands (arguments) are evaluated before the function is invoked, destroying the short-circuit property.
* **Sequencing Changes:** Prior to C++17, the evaluation order of the operands in an overloaded `||` was unsequenced. Since C++17, the left operand is sequenced before the right operand, but both are still unconditionally evaluated.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C++ Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
