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

`long` is a fundamental, signed integral data type in C++ guaranteed by the standard to be at least 32 bits in width. It is designed to represent whole numbers, though its exact memory footprint is compiler- and architecture-dependent based on the underlying data model.

## Memory Size and Data Models

Unlike fixed-width integer types (e.g., `int32_t`, `int64_t`), the size of `long` varies across platforms:

* **Standard Guarantee:** >= 32 bits.
* **LLP64 Data Model (64-bit Windows):** `long` is 32 bits (same size as `int`).
* **LP64 Data Model (64-bit Linux/macOS):** `long` is 64 bits.
* **ILP32 Data Model (32-bit systems):** `long` is 32 bits.

## Syntax and Aliases

The `long` keyword can be used alone or combined with `int` and signedness modifiers. By default, `long` is signed.

```cpp theme={"dark"}
// The following declarations are strictly equivalent:
long val1 = 100;
long int val2 = 100;
signed long val3 = 100;
signed long int val4 = 100;

// Unsigned variant (guaranteed >= 32 bits, strictly non-negative):
unsigned long uval1 = 200;
unsigned long int uval2 = 200;
```

## Literals

To explicitly type an integer literal as `long`, append the `L` or `l` suffix. For `unsigned long`, use `UL`, `Ul`, `uL`, or `ul`. Uppercase is standard practice to avoid visual confusion between the lowercase letter `l` and the number `1`.

```cpp theme={"dark"}
auto a = 2147483647L;  // Type deduced as long
auto b = 4294967295UL; // Type deduced as unsigned long
```

## Value Ranges

The minimum and maximum representable values depend on the platform's bit width. These boundaries can be queried programmatically using the `<limits>` header.

```cpp theme={"dark"}
#include <iostream>
#include <limits>

int main() {
    // Minimum value: typically -2147483648 (32-bit) or -9223372036854775808 (64-bit)
    std::cout << std::numeric_limits<long>::min() << '\n';

    // Maximum value: typically 2147483647 (32-bit) or 9223372036854775807 (64-bit)
    std::cout << std::numeric_limits<long>::max() << '\n';

    // Unsigned maximum: typically 4294967295 (32-bit) or 18446744073709551615 (64-bit)
    std::cout << std::numeric_limits<unsigned long>::max() << '\n';

    return 0;
}
```

## Type Conversion

In expressions involving mixed integral types, C++ applies the usual arithmetic conversions based on integer conversion rank. The C++ standard dictates that the rank of `long` is strictly greater than the rank of `int`, regardless of their actual bit widths on the target architecture.

Consequently, if a binary operation involves an `int` and a `long`, the `int` operand always undergoes an implicit integral conversion to `long` before the expression is evaluated. In strict C++ terminology, this is an *integral conversion*, not an *integral promotion* (which applies exclusively to converting types smaller than `int`, such as `short` or `char`, up to `int`).

```cpp theme={"dark"}
int x = 10;
long y = 20L;

// 'x' undergoes integral conversion to long. 
// The resulting type of 'z' is long.
auto 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>
