C printf using

后端 未结 4 2034
孤城傲影
孤城傲影 2020-12-11 03:18

I was working on this program and I noticed that using %f for a double and %d for a float gives me something completely different. Anybody knows why this happens?

         


        
4条回答
  •  情歌与酒
    2020-12-11 03:46

    It has to do with internal representations of data. You are trying to print a float as if it is an int, which has a completely different internal (binary) representation.

    The double case is similar. You probably have garbage (any data) after the float variable. That garbage is interpreted as part of the double value.

提交回复
热议问题