I saw these two parameters in a C example in a C book but the author didn\'t elaborate what the difference between the two are. I know that %f
specifies that a
For scanf
, %f
reads into a float
, and %lf
reads into a double
.
For printf
: In C99 and later, they both are identical, and they print either a float
or a double
. In C89, %lf
caused undefined behaviour although it was a common extension to treat it as %f
.
The reason that one specifier can be used for two different types in printf
is because of the default argument promotions; arguments of type float
are promoted to double
when used to call a function and not matching a parameter in a function prototype. So printf
just sees a double
in either case.