Use the ll (el-el) long-long modifier with the u (unsigned) conversion. (Works in windows, GNU).
printf("%llu", 285212672);
Answer from John Downey on Stack OverflowUse the ll (el-el) long-long modifier with the u (unsigned) conversion. (Works in windows, GNU).
printf("%llu", 285212672);
%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
Printf, sprintf unsigned long
printf unsigned long long as hex
Why is unsigned long long int behaving as int?
how to do printf with unsigned short long data type?
Videos
For the purpose of the code, the thing I wanna understand is why it goes like this:
include <limits.h>
…
unsigned long long int i;
…
for (i = 1; i < ULLONG_MAX / 10; i *= 10) {
printf(“%u\n”, i);
}
…
This thing prints:
1
10
100
1000
10000
100000
1000000
10000000
100000000
1000000000
1410065408
1215752192
3567587328
It looks like it’s overflowing around 10 billions, so I wonder if it somehow casted it as a normal int instead of an unsigned long long int. In the code I need it to multiply for an ever increasing number, until I hit the ceiling being ULLONG_MAX, but I don’t know why it behaves like this; something’s wrong with my rig? I’m running this code on a virtual box with Linux, my rig is 64 bit.
Any help is appreciated