problem with printf function?

前端 未结 5 1879
Happy的楠姐
Happy的楠姐 2020-12-20 03:28

i wrote the following program

 #include 

 main()
 {
 int i = 2;
 float c = 4.5;
 printf(\"%d\\n\",c);
 printf(\"%f\\n\",i);
 return 0;
 }
         


        
5条回答
  •  余生分开走
    2020-12-20 04:25

    an integer and a float have a different internal representation, so you must not mistake the printf %f with %d to avoid unpredictable results. People uses C expecially because C is fast, and it is fast just because it leave all under the programmer responsibility. So don't expect printf do some magic conversion under the hood because it just won't.

提交回复
热议问题