> ## 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 Unary Plus

The `+` operator in C is a polymorphic token that functions either as a binary addition operator or a unary plus operator, depending on its arity. It operates on arithmetic types (integer and floating-point) and pointer types, triggering specific type conversions and memory scaling rules defined by the C Standard.

## Binary Addition Operator

When used with two operands, `+` computes the sum of its operands.

```c theme={"dark"}
expression1 + expression2
```

The behavior of the binary `+` operator is strictly dictated by the types of its operands:

**1. Arithmetic Addition**
If both operands possess arithmetic types, the compiler applies the **usual arithmetic conversions** before evaluating the expression. This process determines a common real type for the operation, evaluated in the following sequence:

* **Floating-Point Hierarchy:** Floating-point types are evaluated before integer ranks. If either operand is a floating-point type, the hierarchy is `long double` > `double` > `float`. The operand with the lesser type (or any integer type) is implicitly converted to the greater floating-point type.
* **Integer Promotions:** If neither operand is a floating-point type, **integer promotions** are applied to both operands. Types smaller than `int` (e.g., `char`, `short`) are promoted to `int` or `unsigned int`.
* **Integer Conversion Ranks and Signedness:** After promotions, if the integer types still differ, the compiler resolves the common type based on *integer conversion rank* and signedness:
  1. If both operands have the same signedness (both signed or both unsigned), the operand with the lower integer conversion rank is converted to the type with the higher rank.
  2. If the unsigned operand has a rank greater than or equal to the signed operand, the signed operand is converted to the unsigned operand's type.
  3. If the signed operand has a strictly greater rank and can represent *all* possible values of the unsigned operand's type, the unsigned operand is converted to the signed operand's type.
  4. If the signed operand has a strictly greater rank but *cannot* represent all values of the unsigned operand's type, both operands are converted to the unsigned type corresponding to the signed operand's type.

**2. Pointer Arithmetic**
If one operand is a pointer to a **complete object type** and the other is an integer type, the `+` operator performs pointer arithmetic.

* The integer operand is implicitly multiplied by the size (in bytes) of the type the pointer points to (`sizeof(*pointer)`).
* The result is a new pointer of the same type, offset by the scaled integer value.
* **Constraint:** It is a constraint violation to add two pointers together. The `+` operator only supports `pointer + integer` or `integer + pointer`.
* **Constraint:** Pointer arithmetic is invalid on pointers to incomplete types (e.g., `void*`) or function pointers, as their size is not defined by the standard.

## Unary Plus Operator

When used with a single operand, `+` yields the value of its operand after applying type promotions.

```c theme={"dark"}
+expression
```

* The operand must have an arithmetic type.
* The compiler applies **integer promotions** to the operand. For example, applying unary `+` to a `uint8_t` will result in an `int` (assuming `int` can represent all values of `uint8_t` on the target architecture).
* Unlike the unary `-` operator, unary `+` does not alter the sign or mathematical value of the operand; its primary mechanical effect is enforcing integer promotion.

## Undefined Behavior (UB)

The `+` operator can invoke undefined behavior under specific conditions:

* **Signed Integer Overflow:** If the result of an addition between signed integers cannot be represented in the resulting type, the behavior is undefined. (Note: Unsigned integer addition does *not* overflow; it wraps around modulo $2^n$, where $n$ is the number of bits in the result type).
* **Pointer Bounds Violation:** When performing pointer arithmetic, if the resulting pointer points outside the bounds of the array object the original pointer points to (or further than one element past the end of that array), the behavior is undefined.
* **Floating-Point Exceptions:** Depending on the floating-point environment (`<fenv.h>`), adding floating-point numbers that result in overflow, underflow, or NaN (Not a Number) may raise hardware exceptions.

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