Passing Computed Values on to the Outside World
Our example program:
main()
{
int i, j;
i = 5;
j = 3;
printf("sum = %d, product = %d\n", i + j, i * j);
}
included a
printf()
function call
which illustrates how we incorporate values of expressions or
variables into the output that printf generates.
The string that we printed back in
Part 1-3
is really called the
format string
.
This string defines how the output is to be formatted.
Most of the string in this example is composed of characters that
are to be literally written to the output.
The
%d
entries are called
format specifiers
and define how the values of expressions or variables are to
be displayed.
The only one we're using here is
%d
which indicates
that the value is to be displayed as a decimal integer.
The values to be output are found by evaluating the expressions
following the format string.
In this case the expression
i + j
is evaluated and
it's value is printed at the point in the output where the first
%d
is positioned.