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

The `?:` operator, formally known as the conditional operator, is the only ternary operator in the C programming language. It evaluates a controlling scalar expression and, based on whether the result compares unequal to zero, evaluates and yields the value of exactly one of two subsequent expressions.

```c theme={"dark"}
logical_OR_expression ? expression_if_true : expression_if_false
```

## Evaluation Semantics

1. **Control Expression:** The first operand (`logical_OR_expression`) must have a scalar type (arithmetic or pointer). It is evaluated first.
2. **Sequence Point:** There is a strict sequence point immediately after the evaluation of the first operand. All side effects of the first operand are guaranteed to be complete before any further evaluation occurs.
3. **Short-Circuit Evaluation:** The operator guarantees mutually exclusive evaluation of the second and third operands. If the first operand evaluates to a non-zero value, only `expression_if_true` is evaluated. If the first operand evaluates to zero, only `expression_if_false` is evaluated. The unevaluated operand produces no side effects.

## Type Resolution

The type of the result yielded by the conditional operator is determined at compile-time by the types of the second and third operands, regardless of which expression is evaluated at runtime.

The compiler determines the common type using the following rules:

* **Arithmetic Types:** If both the second and third operands have arithmetic types, the *usual arithmetic conversions* are applied to determine a common type. For example, if one is `int` and the other is `double`, the result type of the entire expression is `double`.
* **Structure and Union Types:** If both operands have compatible structure or union types, the result has that compatible structure or union type.
* **Void Types:** If both operands are `void` expressions, the result is a `void` expression.
* **Pointer Types:**
  * If both are pointers to compatible types, the result is a pointer to the composite type, carrying the combined type qualifiers (e.g., `const`, `volatile`) of both operands.
  * If one operand is a pointer and the other is a null pointer constant (like `NULL` or `0`), the result type is the type of the pointer operand.
  * If one operand is a pointer to an object type and the other is a pointer to `void`, the result is a pointer to an *appropriately qualified* version of `void`. The resulting pointer type combines the type qualifiers of both the object pointer and the `void` pointer.

## Value Category

In C, the result of the conditional operator is always an **rvalue** (a value that does not have a memory address identifiable by the programmer). Unlike in C++, you cannot use the C conditional operator on the left side of an assignment operator.

```c theme={"dark"}
/* Valid C: Yields an rvalue */
int result = (x > y) ? x : y;

/* Invalid C: Attempting to use the result as an lvalue */
((x > y) ? x : y) = 10; /* Compilation error */
```

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