
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Correct Way to Use printf to Print size_t in C/C++
We should use “%zu” to print the variables of size_t length. We can use “%d” also to print size_t variables, it will not show any error. 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.
Example
#include <stdio.h> int main() { size_t a = 20; printf("The value of a : %zu", a); return 0; }
Output
The value of a : 20
In the above program, a variable of size_t length is declared and initialized with a value.
size_t a = 20;
The variables of size_t length is printed as follows −
printf("The value of a : %zu", a);
Advertisements