How does this program work?

前端 未结 13 2119
闹比i
闹比i 2020-11-30 22:44
#include 

int main() {
    float a = 1234.5f;
    printf(\"%d\\n\", a);
    return 0;
}

It displays a 0!! How is that

13条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 23:29

    Since you tagged it with C++ as well, this code does the conversion as you probably expect:

    #include 
    
    int main() {
        float a = 1234.5f;
        std::cout << a << " " << (int)a << "\n";
        return 0;
    }
    

    Output:

    1234.5 1234
    

提交回复
热议问题