Home Segments Index Top Previous Next

23: Mainline

In the second instance, the display function displays the result of an arithmetic computation:

printf ("%f", (10.2 + 12.0 + 13.2) / 3); 

Here you hand the printf function a character string and an arithmetic expression. The character string, in this example, consists entirely of a print specification, %f, marked as such by a percent sign, %. The %f print specification tells C that a floating-point number is to be displayed. In the example, the particular floating-point number to be displayed is provided by the expression (10.2 + 12.0 + 13.2) / 3. Thus, the print specification is paired with an arithmetic expression:

          *-------* 
          |       | 
          |       | 
          v   ------------------------- 
printf ("%f", (10.2 + 12.0 + 13.2) / 3));