The correct way to print size_t variables is use of “%zu”. In “%zu” format, z is a length modifier and u stand for unsigned type. The following is an example to print size_t variable. In the above program, a variable of size_t length is declared and initialized with a value.What is a size_t in C++?
C Standard defines it as the type returned by the sizeof operator; aside from being unsigned and a sort of integral type, the size_t can be pretty much anything which size can accommodate the biggest value expected to be returned by sizeof (). Consequently the format string to be used for a size_t may vary depending on the server.What is the size_T type in C?
What is the size_t data type in C? size_t is an unsigned integral data type which is defined in various header files such as: It’s a type which is used to represent the size of objects in bytes and is therefore used as the return type by the sizeof operator.Can%zu be used to print a size_t value?
For C99 and C11, the standard explicitly states that %zu can be used to print size_t values. One should definitely not resort to using a uint32_t / uint64_t format specifier to print a size_t, as there's no guarantee that those types are compatible. – autistic Sep 20 '17 at 4:19