Correct format specifier for return value of sizeof() in C

You’re trying to print the return value of sizeof operator, which is usually of type size_t.

It appears, in your case, size_t is a typedef of long unsigned int, so it demands it’s compatible format specifier %lu to be used. The returned value here does not matter, your problem is with the type mismatch.

Note: To have a portable code, it’s safe to use %zu, on compilers based on C99 and forward standards.

Leave a Comment