I\'ve never bothered to look for printf as I started learning C++ without C. Now i want to use formatted output in some project. so I\'m looking for some references that can exp
Because %d
is for printing integers, not floats. You need one of the floating point format strings, like %f
.
The usual conversions between data types don't work here because printf
is a varargs-type function where you can basically push whatever you want onto the stack (or equivalent if your implementation is not stack-based) and, if it doesn't match what's in your format string, all bets are off - it's undefined behaviour.
See here for one of the things that can go wrong when you have such a mismatch.