Skip to main content

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.

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: 00 to 26412^{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.
// 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.
#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.
#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.
#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 2N2^N, where NN is the number of bits in the type.
unsigned long long max_val = 18446744073709551615ULL;
// Guaranteed to wrap around to 0 due to modulo arithmetic
unsigned long long wrapped_val = max_val + 1; 
Master C++ with Deep Grasping Methodology!Learn More