> ## 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 Greater Than

The `>` (greater than) operator is a binary relational operator that evaluates whether the value of its left operand is strictly greater than the value of its right operand. It yields an `int` result of `1` if the condition is true, and `0` if the condition is false.

```c theme={"dark"}
operand1 > operand2
```

## Technical Mechanics

* **Return Type:** The result of the `>` operator is always of type `int`, regardless of the types of the operands. C does not natively return a boolean type from relational operators.
* **Associativity:** Left-to-right. An expression like `a > b > c` is parsed as `(a > b) > c`. Because the result of `(a > b)` is either `0` or `1`, the subsequent comparison is evaluated as `0 > c` or `1 > c`.
* **Precedence:** The `>` operator has lower precedence than arithmetic operators (like `+`, `-`, `*`, `/`) but higher precedence than equality operators (`==`, `!=`) and logical operators (`&&`, `||`).

## Operand Rules and Type Promotion

The operator accepts operands of real type (integer or floating-point) or pointer type, governed by strict rules defined by the C Standard:

**1. Arithmetic Operands**
When both operands have arithmetic types, the compiler applies the **usual arithmetic conversions** before performing the comparison to establish a common real type.

* **Integer Promotions:** Operands of lower integer conversion ranks (e.g., `char`, `short`) are first promoted to `int` if `int` can represent all values of the original type. Otherwise, they are promoted to `unsigned int` (e.g., an `unsigned short` on a system where `short` and `int` are both 16-bit).
* **Floating-Point Hierarchy:** Floating-point conversions are handled by a separate hierarchy, distinct from integer conversion ranks. If either operand is a floating-point type, the operand with the lower type is converted to the higher type (e.g., comparing an `int` and a `double` causes the `int` to be converted to `double`).
* **Integer Conversion Rank and Mixed Signs:** If both operands are integers of different types, integer conversion ranks dictate the promotion.
  * If the operands have the same rank but different signedness, the signed operand is converted to unsigned.
  * If the unsigned operand has a lower rank, and the signed operand's type can represent all values of the unsigned type, the unsigned operand is converted to the signed type.
  * If the higher-rank signed type *cannot* represent all values of the lower-rank unsigned type (e.g., a 32-bit `long` and a 32-bit `unsigned int`), *both* operands are converted to the unsigned version of the higher-rank type.
* **Negative to Unsigned Conversion:** When a signed integer is converted to an unsigned integer during these promotions, a negative value is mathematically converted to a large positive unsigned value (e.g., `-1` becomes `UINT_MAX`). This can lead to unexpected comparison results if not carefully managed.

**2. Pointer Operands**
Pointers can be compared using `>` if both point to compatible object types.

* The C standard abstracts memory and does not mandate or assume virtual memory. Pointer comparison is strictly defined in terms of array subscripts and object layouts.
* Comparing pointers using `>` is strictly valid only if both pointers point to elements within the same array object (or one past the last element), or to members of the same aggregate object. In C, only arrays and structures are aggregate types.
* For arrays, a pointer to an element with a higher subscript compares greater than a pointer to an element with a lower subscript.
* For structures, pointers to members declared later in the `struct` compare greater than pointers to members declared earlier.
* Comparing pointers to distinct, unrelated objects results in **undefined behavior**.

## Syntax Visualization

```c theme={"dark"}
int x = 10;
int y = 5;
double z = 15.5;

// Standard integer comparison
int res1 = x > y;       // Evaluates to 1 (int)

// Mixed-type comparison (x is converted to double)
int res2 = z > x;       // Evaluates to 1 (int)

// Associativity evaluation: (x > y) > 0  ->  (1) > 0
int res3 = x > y > 0;   // Evaluates to 1 (int)

// Pointer comparison (valid within the same array)
int arr[5];
int *p1 = &arr[0];
int *p2 = &arr[3];
int res4 = p2 > p1;     // Evaluates to 1 (int)

// Pointer comparison (valid within the same aggregate object)
struct Data {
    int first_member;
    int second_member;
} obj;
int *ptr1 = &obj.first_member;
int *ptr2 = &obj.second_member;
int res5 = ptr2 > ptr1; // Evaluates to 1 (int)
```

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