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

`unsigned long long` is a fundamental, non-negative integer data type in C++ (introduced in C++11) that guarantees a minimum width of 64 bits. Because it is an unsigned type, it omits the sign bit, utilizing all available memory bits exclusively to represent the magnitude of the value.

## Technical Specifications

* **Minimum Width:** 64 bits.
* **Minimum Range:** $0$ to $2^{64} - 1$.
* **Exact Maximum Value (for 64-bit width):** `18,446,744,073,709,551,615`.
* **Standard Macro:** `ULLONG_MAX` (defined in `<climits>`).
* **Memory Footprint:** `sizeof(unsigned long long)` evaluates to at least `64 / CHAR_BIT` bytes. While this is 8 bytes on systems where `CHAR_BIT == 8`, the exact byte size depends on the architecture's byte width.

## Syntax and Literals

To explicitly define an integer literal as an `unsigned long long`, append the `ull` or `ULL` suffix to the numeric value.

In standard C++, decimal literals without a suffix are strictly signed (`int`, `long`, or `long long`). If an unsuffixed decimal value exceeds the maximum representable value of `long long`, the program is ill-formed and will result in a compilation error. Conversely, for hexadecimal, octal, and binary literals, the compiler automatically deduces `unsigned long long` if the value requires it to fit, even without a suffix.

```cpp theme={"dark"}
// Explicit declaration using the ULL suffix
unsigned long long decimal_val = 18446744073709551615ULL;

// Hexadecimal representation (suffix optional if value exceeds long long)
unsigned long long hex_val = 0xFFFFFFFFFFFFFFFFull;

// Binary representation (C++14 and later)
unsigned long long bin_val = 0b1111111111111111111111111111111111111111111111111111111111111111ULL;

// Using digit separators for readability (C++14 and later)
unsigned long long readable_val = 18'446'744'073'709'551'615ULL;
```

## Type Limits

You can programmatically query the properties of `unsigned long long` using the `<limits>` header.

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

int main() {
    constexpr unsigned long long min_val = std::numeric_limits<unsigned long long>::min(); // Always 0
    constexpr unsigned long long max_val = std::numeric_limits<unsigned long long>::max();
    
    std::cout << "Min: " << min_val << "\n";
    std::cout << "Max: " << max_val << "\n";
    
    return 0;
}
```

## Fixed-Width Integer Relationship

The `<cstdint>` header provides `uint64_t`, an exact-width integer type that is strictly 64 bits. The underlying type of `uint64_t` depends on the operating system's data model (LP64 vs. LLP64), not the CPU architecture.

* **LLP64 Systems (e.g., 64-bit Windows):** `uint64_t` is typically a `typedef` for `unsigned long long`.
* **LP64 Systems (e.g., 64-bit Linux, macOS):** `uint64_t` is typically a `typedef` for `unsigned long`.

Because of this distinction, treating `uint64_t` and `unsigned long long` as strictly interchangeable types can lead to type-matching compilation errors in templates or function overloads.

```cpp theme={"dark"}
#include <cstdint>
#include <type_traits>

// Evaluates to true on Windows (LLP64), but false on Linux/macOS (LP64)
constexpr bool is_same = std::is_same_v<uint64_t, unsigned long long>;
```

## Formatting and I/O

When using C++ streams (`std::cout`, `std::cin`), the standard library provides overloaded operators that handle `unsigned long long` natively. However, when interfacing with C-style I/O functions like `std::printf` or `std::scanf`, you must use the `%llu` format specifier.

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

int main() {
    unsigned long long value = 42ULL;

    // C-style output requires the %llu specifier
    std::printf("Value: %llu\n", value);
    
    return 0;
}
```

## Overflow Behavior

Unlike signed integers, where overflow invokes Undefined Behavior (UB), unsigned integer overflow is strictly defined by the C++ standard. If an operation exceeds the maximum representable value, the result is reduced modulo $2^N$, where $N$ is the number of bits in the type.

```cpp theme={"dark"}
unsigned long long max_val = 18446744073709551615ULL;
// Guaranteed to wrap around to 0 due to modulo arithmetic
unsigned long long wrapped_val = max_val + 1; 
```

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