Why does printf implicit float to int conversion not work?

前端 未结 3 535
暗喜
暗喜 2021-01-25 11:27

Please help me in understanding the following C Output:

#include
int main() {
    float x = 4.0;
    printf(\"%f\\n\",x);
    printf(\"%d\\n\",x);         


        
3条回答
  •  春和景丽
    2021-01-25 11:47

    You're not printing y, you're printing x again.

    As a side note, printf can't do conversions. So passing a float when a %d is expected is undefined behavior.

提交回复
热议问题