The function printf provides the formatted output conversion in the C programming language. Its function signature is as follows:
int printf (const char *format, [arg1, arg2,] ...);
printf converts, formats, and prints its arguments on the standard output under the control of format. And it returns the number of characters printed.

The format string contains two kind of objects, 'ordinary or literal characters', which are copied to the output stream as such, and 0 or more 'conversion specifications', each of which is used to convert and print the next successive argument to the printf.

The conversion specifications start with the '%' symbol and end with a conversion symbol. Between these two, there can exist, in order:

  • A minus sign ('-') to specify left adjustment of the converted argument. The default adjustment is 'right', which can also be explicitly specified using a '+' symbol.
  • A number specifying minimum field width. The converted argument will be printed in a field atleast this wide. Padding is used to make up if needed.
  • A period ('.'), to separate the field width from precision.
  • A number, the precision, specifying maximum number of characters to be printed from a string, or the number of digits after the decimal point of a floating point value, or the minimum number of digits for an integer.
  • An 'h' if the integer is to be printed as a short, or 'l' if as a long.

A width or precision may also be specified as *, in which case the value is computed by converting the next argument (must be an integer). For example:

printf("%.*s", max, s);
prints at most max characters from string s.


Thanks to ariels for pointing out a mistake in the signature, it's const char *, not just char *