Practice mode C Language

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.