Since you specified %d
instead of %f
, what you really see is a binary representation of d
as an integer.
Also, since the data types do not match, the code does have undefined behavior.
EDIT:
Now, to explain why you do not see 2
:
float
gets promoted to double
on the stack. The double
type (in this case) is 8 bytes. However, since your printf
specifies two integers (both 4 bytes in this case), you see the binary representations of 1.0
as a double
type. 2 does not print because it exceeds 8 bytes expected by your printf
.
source share