"printf" stands for "print formatted"
Overview
Many programming languages implement a printf
function to output a formatted string. It originated from the C programming language, where it has a prototype similar to the following:
int printf(const char *format, ...);
The string constant format
provides a description of the output, with placeholders marked by %
escape characters, to specify both the relative location and the type of output that the function should produce. The return value yields the number of printed characters.
printf("Color %s, number1 %d, number2 %05d, hex %#x, float %5.2f, unsigned value %u.\n",
"red", 123456, 89, 255, 3.14159, 250);
will print the following line (including new-line character, \n):
Color red, number1 123456, number2 00089, hex 0xff, float 3.14, unsigned value 250.
The printf
function returns the number of characters printed, or a negative value if an output error occurs.