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 standard unsigned integer data type in C, introduced in the C99 standard, designed to represent strictly non-negative whole numbers. It shares the highest integer conversion rank among standard integer types with its signed counterpart, long long int, and guarantees a minimum storage width of 64 bits.

Memory Size and Value Range

According to the C standard, unsigned long long must be at least 64 bits wide. Because it is an unsigned type, the most significant bit (MSB) is not used as a sign bit; instead, all bits contribute to the magnitude of the number, shifting the representable range entirely to non-negative values.
  • Minimum Value: 0
  • Maximum Value: 18,446,744,073,709,551,615 (264 - 1)
The exact maximum value for a specific compiler implementation is defined by the ULLONG_MAX macro, which is accessible by including the <limits.h> header.

Syntax and Declaration

The type can be declared using either unsigned long long or the fully qualified unsigned long long int. Both are semantically identical to the compiler.
// Standard declaration
unsigned long long var1;

// Fully qualified declaration
unsigned long long int var2;

// Declaration with initialization (implicit conversion from int)
unsigned long long var3 = 0;

Literals and Suffixes

When assigning constant values to an unsigned long long, a suffix is not universally required. Small integer literals (such as 10 or 0) are evaluated as type int and undergo an implicit conversion to unsigned long long upon assignment. However, appending the ULL or ull suffix to an integer literal is strictly required in specific scenarios:
  1. Exceeding Signed Limits: When a decimal literal exceeds the maximum representable value of a signed long long int (e.g., 18446744073709551615), without the suffix, the compiler may reject the literal as too large for standard signed types.
  2. Constant Expression Evaluation: When you need to force 64-bit arithmetic during the evaluation of an expression to prevent integer overflow (e.g., bitwise shifting 1 by 40 positions).
// Implicit conversion from int (no suffix needed)
unsigned long long small_val = 42;

// Suffix required: literal exceeds signed long long maximum
unsigned long long max_val = 18446744073709551615ULL;

// Suffix required: forces 64-bit arithmetic to prevent overflow during the shift
unsigned long long shifted_val = 1ULL << 40;

// Hexadecimal literal with ull suffix
unsigned long long hex_val = 0xFFFFFFFFFFFFFFFFull;

Format Specifiers

To perform standard I/O operations with unsigned long long using functions like printf or scanf, the %llu format specifier is required. The ll acts as a length sub-specifier indicating “long long”, and the u denotes an unsigned decimal integer. For hexadecimal output, %llx or %llX is used.
#include <stdio.h>

int main(void) {
    unsigned long long value = 1234567890123456789ULL;
    
    // Outputting the value in decimal and hexadecimal
    printf("Decimal: %llu\n", value);
    printf("Hexadecimal: %llX\n", value);
    
    // Reading the value from standard input
    scanf("%llu", &value);
    
    return 0;
}
Master C with Deep Grasping Methodology!Learn More