Print Unsigned Long Long in Hexadecimal Format – C Guide

c++integerprintf

I am trying to print out an unsigned long long like this:

  printf("Hex add is: 0x%ux ", hexAdd);

but I am getting type conversion errors since I have an unsigned long long.

Best Answer

You can use the same ll size modifier for %x, thus:

#include <stdio.h>

int main() {
    unsigned long long x = 123456789012345ULL;
    printf("%llx\n", x);
    return 0;
}

The full range of conversion and formatting specifiers is in a great table here: