printf format string refers to a control parameter used by a class of functions in the input/output libraries of C and many other programming languages. The string is written in a simple template language: characters are usually copied literally into the function's output, but format specifiers, which start with a%
character, indicate the location and method to translate a piece of data (such as a number) to characters. https://en.wikipedia.org/wiki/Printf_format_string​
savings
variable is defined as a floating value of 345.82
, which is printed to the screen with printf
, using the format string Savings: $%f
:%f
in the format string tells the printf()
to print the value of savings
as a floating-point value.savings
value was printed with 6 decimal places:$345.820000
is not the precision we need when dealing with money, so it would look better if the value only had 2 decimal places, such as $345.82
. With the help of format string Savings: $%.2f
, we can achieve exactly that:printf
, which means that the user's supplied string is used as a format string for the printf
function:Testing: 0x%x
: