How do you format an unsigned long long int using printf? How do you format an unsigned long long int using printf? c c

How do you format an unsigned long long int using printf?


Use the ll (el-el) long-long modifier with the u (unsigned) conversion. (Works in windows, GNU).

printf("%llu", 285212672);


You may want to try using the inttypes.h library that gives you types such asint32_t, int64_t, uint64_t etc.You can then use its macros such as:

uint64_t x;uint32_t y;printf("x: %"PRId64", y: %"PRId32"\n", x, y);

This is "guaranteed" to not give you the same trouble as long, unsigned long long etc, since you don't have to guess how many bits are in each data type.


%d--> for int

%u--> for unsigned int

%ld--> for long int or long

%lu--> for unsigned long int or long unsigned int or unsigned long

%lld--> for long long int or long long

%llu--> for unsigned long long int or unsigned long long