C Programming – Why One printf() Can’t Print Two 64-bit Values Simultaneously?

c++printf

I am working on a 32-bit system. When I try to print more than one 64 bit value in a single printf, then it cannot print any further (i.e. 2nd, 3rd, …) variable values.

example:

uint64_t a = 0x12345678;
uint64_t b = 0x87654321;
uint64_t c = 0x11111111;

printf("a is %llx & b is %llx & c is %llx",a,b,c);

Why can this printf not print all values?

I am modifying my question

printf("a is %x & b is %llx & c is %llx",a,b,c);

by doing this result is : a is 12345678 & b is 8765432100000000 & c is 1111111100000000

if i am not printing a's value properly then why other's value's are gona change??

Best Answer

You should use the macros defined in <inttypes.h>

printf("a is %"PRIx64" & b is %"PRIx64" & c is %"PRIx64"\n",a,b,c);

It is ugly as hell but it's portable. This was introduced in C99, so you need a C99 compliant compiler.

Related Question