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

The `short` (or `short int`) data type in C is a primitive integer type that allocates less or equal memory compared to a standard `int`. By default, it represents signed whole numbers and is guaranteed by the C Standard to be at least 16 bits (2 bytes) in width, strictly adhering to the architectural constraint `sizeof(short) <= sizeof(int)`.

## Type Variants and Syntax

The `short` keyword can be combined with signedness modifiers. If no modifier is provided, the type defaults to `signed`. The `int` keyword is optional and usually omitted in idiomatic C.

```c theme={"dark"}
short a = 10;               // Implicitly signed, equivalent to 'signed short int'
signed short b = -500;      // Explicitly signed
unsigned short c = 65000;   // Unsigned, strictly non-negative
```

## Size and Value Ranges

While the exact byte size is architecture-dependent, a `short` is almost universally implemented as a 16-bit two's complement integer. The exact limits for the target compiler are defined via macros in the `<limits.h>` header.

| Type             | Minimum Size | Standard Range (16-bit) | `<limits.h>` Macros     |
| :--------------- | :----------- | :---------------------- | :---------------------- |
| `signed short`   | 16 bits      | -32,768 to 32,767       | `SHRT_MIN` / `SHRT_MAX` |
| `unsigned short` | 16 bits      | 0 to 65,535             | `0` / `USHRT_MAX`       |

## Format Specifiers

When performing I/O operations with standard library functions like `printf` or `scanf`, the `h` (half) length sub-specifier must be prepended to the base integer format specifiers.

```c theme={"dark"}
#include <stdio.h>

int main(void) {
    short s_val = -1234;
    unsigned short u_val = 56789;

    // %hd for signed decimal
    printf("Signed: %hd\n", s_val);
    
    // %hu for unsigned decimal
    printf("Unsigned: %hu\n", u_val);
    
    // %hx or %ho for unsigned hexadecimal or octal
    printf("Hexadecimal: %hx\n", u_val);

    return 0;
}
```

## Integer Promotion

A critical mechanical behavior of `short` in C is **integer promotion**. When a `short` is evaluated in an arithmetic or bitwise expression, the compiler implicitly promotes its value to an `int` (or `unsigned int` if an `int` cannot represent the entire range of the original type) before executing the operation.

```c theme={"dark"}
#include <stddef.h>

void promotion_example(void) {
    short x = 32000;
    short y = 1000;

    // x and y are promoted to 'int' before the addition occurs.
    // The expression (x + y) yields an 'int', not a 'short'.
    size_t expr_size = sizeof(x + y); // Evaluates to sizeof(int), typically 4 bytes

    // Assigning an out-of-range 'int' back to a signed 'short' results in Implementation-Defined Behavior.
    // Unlike unsigned types (which guarantee modulo arithmetic/truncation), signed conversion is compiler-dependent.
    short z = x + y; 
}
```

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