First of all, the wrong printf() format string is undefined behavior. Now that itβs said, hereβs what actually happens in your case:
In vararg functions such as printf() , integers smaller than int move up to int , and floats smaller than double move up to double .
As a result, your 27.881 converted to an 8-byte double, as it is passed to printf() . Therefore, the binary representation no longer matches the float .
The format string %d expects a 4-byte integer. This way you will print the bottom 4 bytes of the view with a double precision of 27.881 . (assuming little-endian)
* Actually (subject to strict FP) you see the bottom 4 bytes of 27.881 after it was added to the float , and then it moves to double .
source share