CKTIS / C++
Integer literal suffix ULL
The built-in suffix `ULL` gives a representable integer literal the type `unsigned long long`. It is not a literal operator or part of a number's sign.
Version: ISO C++23; implementation support may vary
Syntax
42ULL, 0x2AULL, 052ULL, 0b101010ULL
Suffix spelling: U or u combined with LL or ll, in either order.In C++23, write the integer suffix ULL immediately after the digits: 42ULL has type unsigned long long, while 42 has type int. That difference can change which overload is selected. The suffix works with decimal, hexadecimal, octal, and binary notation. Put U or u before or after LL or ll; mixed-case lL is not allowed.
unsigned long long has at least 64 value bits, not necessarily exactly 64. If the literal's value does not fit, the implementation may use a suitable extended unsigned integer type. If no permitted type can represent it, the program is ill-formed; the literal's value does not wrap.
A unary sign is not part of the literal. In -1ULL, unary - produces the maximum unsigned long long value. Unsigned arithmetic is modulo 2^N, where N is the number of value bits. If scaling must be exact, check that the count is no greater than the type's maximum divided by the scale factor before multiplying.
Examples
#include <iostream>
#include <limits>
#include <type_traits>
int main() {
static_assert(std::is_same_v<decltype(42), int>);
static_assert(std::is_same_v<decltype(42ULL), unsigned long long>);
static_assert(-1ULL == std::numeric_limits<unsigned long long>::max());
std::cout << 3ULL * 1024ULL << '\n'
<< 2ULL * 1024ULL * 1024ULL << '\n';
}
Result
3072 2097152
The `static_assert` checks cover types and unary negation. The program prints `3072` and `2097152`, the byte counts for 3 KiB and 2 MiB.
Related lessons
- C++ · Lesson 60 · Advanced · Version: 3