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

The `long` keyword in C is a fundamental integer data type (implicitly `long int`) that guarantees a minimum storage size of 32 bits. It provides a larger or equal value range compared to the standard `int` type, depending on the compiler and the target architecture's data model.

## Memory Size and Data Models

The exact byte size of `long` is implementation-defined. While the C standard mandates a minimum of 32 bits, its actual size diverges across different 64-bit environments:

* **ILP32 (32-bit systems):** 32 bits (4 bytes).
* **LLP64 (64-bit Windows):** 32 bits (4 bytes).
* **LP64 (64-bit Unix/Linux/macOS):** 64 bits (8 bytes).

## Syntax and Modifiers

By default, `long` is signed, utilizing two's complement representation. It can be explicitly modified using the `unsigned` keyword to shift the representable range to strictly non-negative values, effectively doubling the maximum positive limit.

```c theme={"dark"}
// Signed long declarations (all are semantically identical)
long a;
long int b;
signed long c;
signed long int d;

// Unsigned long declarations (all are semantically identical)
unsigned long e;
unsigned long int f;
```

## Literal Suffixes

When parsing integer literals, the C compiler assigns the `int` type by default if the value fits. To explicitly force a literal to be evaluated as a `long`, append the `L` or `l` suffix (uppercase `L` is standard practice to avoid visual confusion with the digit `1`). For unsigned variants, combine `U` and `L`.

```c theme={"dark"}
long signed_val = 2147483647L;
unsigned long unsigned_val = 4294967295UL;
```

## Format Specifiers

When interfacing with standard I/O functions like `printf` and `scanf`, specific length modifiers (`l`) must be prepended to the integer conversion specifiers to prevent undefined behavior resulting from stack misalignment or truncation.

* `%ld` or `%li`: Signed `long`
* `%lu`: Unsigned `long`
* `%lx` or `%lX`: Unsigned `long` in hexadecimal
* `%lo`: Unsigned `long` in octal

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

int main(void) {
    long val = -123456L;
    unsigned long uval = 123456UL;

    printf("Signed: %ld\n", val);
    printf("Unsigned: %lu\n", uval);
    
    return 0;
}
```

## Standard Limits

The absolute minimum and maximum representable values for the specific compilation target are exposed via macros in the `<limits.h>` standard library header.

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

int main(void) {
    long min_val = LONG_MIN;            // Guaranteed to be <= -2147483647
    long max_val = LONG_MAX;            // Guaranteed to be >= +2147483647
    unsigned long umax_val = ULONG_MAX; // Guaranteed to be >= +4294967295
    
    return 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>
