Replacing the %f with %d | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

Replacing the %f with %d

What happens if you replace the f with a d? Th output is a different number, but where does it come from?

10th Dec 2018, 11:43 AM
Laura Schamul
Laura Schamul - avatar
2 Answers
+ 7
The output is due to undefined behaviour. The float is represented usually in IEEE754 binary format (sign, then exponent, and then mantissa) and maybe that was interpreted as an integer. Or something else happened. The reason for this is explained here:
10th Dec 2018, 11:55 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 5
Very interesting question! Great answer Kinshuk. 8) Also, my favorite Wiki page of all times is LOL!
10th Dec 2018, 12:08 PM
Babak - avatar