Name
printf
Synopsis
Writes formatted output to the standard output stream
#include <stdio.h> intprintf( const char * restrictformat, ... );
The printf() function
converts various kinds of data into string representations for
output, and substitutes them for placeholders in the string
referenced by the mandatory pointer argument,
format. The resulting output string is
then written to the standard output stream. The return value of
printf() is the number of
characters printed, or EOF to
indicate that an error occurred.
The placeholders in the string argument are called conversion specifications, because they also specify how each replacement data item is to be converted, according to a protocol described shortly.
The optional arguments, represented by the ellipsis in the function prototype, are the data items to be converted for insertion in the output string. The arguments are in the same order as the conversion specifications in the format string.
Conversion specification syntax
For a general overview of data output with printf(), see "Formatted Output" in Chapter 13. This section describes
the syntax of conversion specifications in the printf() format string in detail. The
conversion specifications have the following syntax:
%[flags][field width][.precision][length modifier]specifier
The flags consist of one or more of
the characters +, ' ' (space), -, 0,
or #. Their meanings are as follows:
+Add a plus sign before positive numbers.
' 'Add a space before positive numbers (not applicable ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access