Name
printf
Synopsis
int printf(stringformat[, mixedarg1...])
Outputs a string created by using
format and the given arguments. The
arguments are placed into the string in various places denoted by
special markers in the format
string.
Each marker starts with a percent sign (%) and consists of the following elements,
in order. Except for the type specifier, the specifiers are all
optional. To include a percent sign in the string, use %%.
An optional sign specifier that forces a sign (– or +) to be used on a number. By default, only the – sign is used on a number if it’s negative. Additionally, this specifier forces positive numbers to have the + sign attached.
A padding specifier denoting the character to use to pad the results to the appropriate string size (given below). Either 0, a space, or any character prefixed with a single quote may be specified; padding with spaces is the default.
An alignment specifier. By default, the string is padded to make it right-justified. To make it left-justified, specify a dash (
-) here.The minimum number of characters this element should contain. If the result would be less than this number of characters, the above specifiers determine the behavior to pad to the appropriate width.
For floating-point numbers, a precision specifier consisting of a period and a number; this dictates how many decimal digits will be displayed. For types other than float, this specifier is ignored.
Finally, a type specifier. This specifier tells
printf()what type of data ...
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