How do you printf an unsigned long long int(the format specifier for unsigned long long int)?

Question!
#include <stdio.h>
int main() {
    unsigned long long int num = 285212672; //FYI: fits in 29 bits
    int normalInt = 5;
    printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt);
    return 0;
}

Output:

My number is 8 bytes wide and its value is 285212672l. A normal number is 0.

I assume this unexpected result is from printing the unsigned long long int. How do you printf() an unsigned long long int?

By : andrewrk


Answers

In addition to what people wrote years ago:

  • you might get this error on gcc/mingw:

main.c:30:3: warning: unknown conversion type character 'l' in format [-Wformat=]

printf("%llu\n", k);

Then your version of mingw does not default to c99. Add this compiler flag: -std=c99.



In Linux it is %llu and in Windows it is %I64u

Although I have found it doesn't work in Windows 2000, there seems to be a bug there!



Hex:

printf("64bit: %llp", 0xffffffffffffffff);

Output:

64bit: FFFFFFFFFFFFFFFF
By : lama12345


This video can help you solving your question :)
By: admin