First you are printing the memory address of the variable when you use the &
operator:
printf("%10.2f", &d);
// ^---
Then the f
formatter, for floating-point values, as well as documentation indicates:
Decimal floating point, lowercase
However, if you print a int
where the function expects a float
will not display the number correctly because a float
is not stored in the same way as a int
in relation to the bits. p>
If you want to still print the integer as if it were a float
you can do a conversion to float
at the time of printing that already gives you the result you would expect:
printf("%10.2f", (float)d);
Still, if you did all integer operations the result will always be an integer, so the decimal part will always be .00
Recommended reading:
What is the meaning of the & amp; & amp; ; "(And commercial) in C language?