Using printf function

后端 未结 5 831
时光说笑
时光说笑 2021-01-22 13:01

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

5条回答
  •  孤街浪徒
    2021-01-22 13:21

    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.

提交回复
热议问题