What is the function of "f"

In the code below,
In the 8th row,
printf ("The Total is %f",f);

what is the function of third "f" which is wrriten at the end of the line
ie. ,f);

If i removed that, the output value is changing.

1
2
3
4
5
6
7
8
9
10
#include <stdio.h>
int main ()
{
int a = 3, b = 5;
float c = 9.5, d = 2.3;
double f;
f = a + b + c - d;
printf ("The Total is %f",f);
return 0;
}
Last edited on
Well, you have to tell printf what to print out no? you want it to print out f, which is equal to a+b+c-d.
I think you're actually confused about the %f in the first parameter to printf(). The first parameter is a string that can contain format specifiers like %f. When it sees %f, it looks for another parameter to the printf() function. That param must be a double. printf() converts the double to a string and substitutes the string for %f in the output.
Topic archived. No new replies allowed.