C - Need explanation on printf options' behavior -


hi have double variable named outputsamplerate value 0x41886a0000000000

i'm trying different combination of printf options , confused output.

here code:

    printf("\n\noutputsamplerate  0x%16x       \n", outputsamplerate);     printf("outputsamplerate  0x%llx       \n", outputsamplerate);     printf("outputsamplerate  0x%.llx       \n", outputsamplerate);     printf("outputsamplerate  0x%.16x       \n", outputsamplerate);     printf("outputsamplerate  0x%16llx       \n", outputsamplerate);     printf("outputsamplerate  0x%.16llx       \n\n", outputsamplerate); 

here printout on console:

outputsamplerate %llx  0x               0 outputsamplerate %16x  0x41886a0000000000 outputsamplerate %.llx  0x41886a0000000000 outputsamplerate %.16x  0x0000000000000000 outputsamplerate %16llx  0x41886a0000000000 outputsamplerate %.16llx 0x41886a0000000000 

please correct me if i'm wrong:

%llx    print long long (64 bit) in hex representation %16x    print 16 digits, ignore leading 0s in hex representation %.llx    ????what this? %.16x    print @ least 16 digits in hex repesentation %16llx   print 16 digits long long in hex representation %.16llx  print @ least 16 digits long long in hex representation 

besides, have following questions:

1. how %llx give me 0x               0  ? 2. why %.llx , %.16x behave differently   ? 

thank input save c newbie.

%llx not mean "print long long in hex". means the argument (has type) long long. if violate requirement, program has undefined behavior.

if want print representation of double, like:

double x; uint64_t x_repr; memcpy(&x_repr, &x, sizeof x_repr); printf("%" prix64 "\n", x_repr); 

Comments