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

The `==` (equality) operator is a binary operator that compares two operands to determine if their evaluated values are equal. It yields an `int` result of `1` if the operands are equal, and `0` if they are not.

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

## Return Type

Regardless of the types of the operands, the result of the `==` operator is always of type `int`. C does not return a boolean type (`bool`) from equality operators, even if `<stdbool.h>` is included.

## Type Promotion and Conversions

When the operands are of different types, the compiler applies implicit conversions before performing the comparison:

* **Usual Arithmetic Conversions:** If both operands are arithmetic types (integer or floating-point), they are promoted to a common type. For example, if comparing an `int` and a `double`, the `int` is promoted to a `double` before the equality check occurs.
* **Pointer Comparison:** Pointers can be compared using `==` if they point to compatible types. Additionally, a pointer can be compared to a `void *` (void pointer) or a null pointer constant (such as `0` or `NULL`).

## Operand Constraints

The `==` operator cannot be applied to all data types:

* **Aggregate Types:** You cannot use `==` to directly compare `struct` or `union` types. The compiler will emit an error. The standard and safest approach is member-by-member comparison. Using memory comparison functions like `memcmp` on structs is a known anti-pattern; structs often contain hidden padding bytes with indeterminate values, which can yield false negatives unless the entire struct memory was explicitly zeroed out prior to initialization.
* **Arrays:** When `==` is used with array identifiers, the arrays undergo *array-to-pointer decay*. The operator compares the memory addresses of the first elements of the arrays, not the contents of the arrays themselves.

## Precedence and Associativity

* **Precedence:** The `==` operator has lower precedence than relational operators (`<`, `<=`, `>`, `>=`) but higher precedence than bitwise operators (`&`, `^`, `|`) and logical operators (`&&`, `||`).
* **Associativity:** It has left-to-right associativity. This dictates the *grouping* of the operands, not the *evaluation order* of the operands themselves. The order in which `operand1` and `operand2` are executed is unsequenced and unspecified in C.

Because of left-to-right associativity, chained equality expressions group sequentially:

```c theme={"dark"}
a == b == c
```

This expression is parsed as `(a == b) == c`. The subexpression `(a == b)` evaluates to either `1` or `0`, and that resulting `int` is then compared to `c`.

## Floating-Point Mechanics

When evaluating IEEE 754 floating-point numbers, the `==` operator adheres to specific hardware-level rules:

* **Precision Loss:** Using `==` to check for exact equality between floating-point numbers is inherently unsafe due to precision loss and rounding errors. For example, `0.1 + 0.2 == 0.3` typically evaluates to `0` because the internal binary representations are not perfectly exact.
* **Zeroes:** Positive zero and negative zero evaluate as equal (`+0.0 == -0.0` yields `1`).
* **NaN:** Not-a-Number (NaN) values are never equal to anything, including themselves. Using the standard `<math.h>` macro, `NAN == NAN` yields `0`.

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