Skip to main content
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.

Type Limits

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

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.

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.

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.
Tired of Poor C++ Skills? Fix That With Deep Grasping!Learn More