Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printf for size_t

Is there any way to give printf a size_t without either casting it first or generating a compiler warning? (I always compile with -Wall.)

like image 742
Nick Avatar asked Nov 10 '10 23:11

Nick


People also ask

What is Size_t in printf?

size_t is an unsigned integral data type which is defined in various header files such as: <stddef.h>, <stdio.h>, <stdlib.h>, <string.h>, < time .h>, <wchar.h> 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.

What is %z in printf?

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.

What does %3f mean in C?

The "precision" modifier is written ". number", and has slightly different meanings for the different conversion specifiers (like d or g). For floating point numbers (e.g. %f), it controls the number of digits printed after the decimal point: 1. printf ( "%.3f" , 1.2 );

What is string formatting in C?

The Format specifier is a string used in the formatted input and output functions. The format string determines the format of the input and output. The format string always starts with a '%' character. The commonly used format specifiers in printf() function are: Format specifier.


1 Answers

printf("%zu", sizeof(whatever));
like image 162
dan04 Avatar answered Sep 22 '22 08:09

dan04