In both cases you pass a bits representing floating-point values, and print them as decimal. The second case is the simple case, here the output is the same as the underlying representation of the floating-point number. (This assumes that the calling convention specified that the value of a float
is passed the same way an int
is, which is not guaranteed.)
However, in the first case, when you pass a float
to a vararg function like printf
it is promoted to a double
. This mean that the value passed will be 64 bits, and printf
will pick up either half of it (or perhaps garbage). In your case it has apparently picked up the 32 least significant bits, as they typically will be all zero after a float
to double
cast.
Just to make it absolutely clear, the code in the question is not valid C, as it's illegal to pass values to printf
that does not match the format specifier.