Which printf() conversion specification is correct for printing a value of type size_t?
Correct answer B. %zu
Explanation
C99 added the z length modifier for size_t, so %zu prints the unsigned value returned by sizeof or strlen correctly on every platform. %lu happens to work where size_t is unsigned long, as on 64-bit Linux, but fails on 64-bit Windows where it is unsigned long long. %d is the wrong size and signedness, and %sz is not a valid specifier.
Answer checked How we write and check questions
Discussion