Why does printf print wrong values?

后端 未结 7 1455
情歌与酒
情歌与酒 2020-12-01 22:19

Why do I get the wrong values when I print an int using printf(\"%f\\n\", myNumber)?

I don\'t understand why it prints fine with %d

相关标签:
7条回答
  • 2020-12-01 23:17

    the problem is... inside printf. the following happens

    if ("%f") {
     float *p = (float*) &a;
     output *p;  //err because binary representation is different for float and int
    }
    
    0 讨论(0)
提交回复
热议问题