English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
We should use '%zu' to print variables of type size_t. We can also use '%d' to print size_t variables, which will not show any errors. The correct way to print a size_t variable is to use '%zu'.
In the format '%zu', 'z' is the length modifier, and 'u' indicates an unsigned type.
The following is an example of printing a size_t variable.
#include <stdio.h> int main() { size_t a = 20; printf("The value of a: %zu", a); return 0; }
Output Result
The value of 'a': 20
In the above program, a variable of type size_t named 'length' is declared and initialized with a value.
size_t a = 20;
The variable 'size_t length' is printed as follows:
printf("The value of a: %zu", a);