Your code has undefined behaviour. The expression b[0]
is a char
(promoted to int
), and the format specifier %f
expects a double
.
(There could be any number of explanations for the output you see. The most urgent one that comes to mind is that a double
is wider than an int
on your platform and garbage memory is read. If you want a slightly more predictable experiment, try passing static_cast<uint64_t>(b[0])
as the argument.)