小编Hon*_*uan的帖子

在示例中,为什么float转换为int打印不同的结果?

#include <stdio.h>
#include <float.h>
#include <stdlib.h>

int main() {
    float x = 3.8, y = 5.2;
    int a, b, c;
    float d = x + y;
    a = d;
    b = (int)(x + y);
    c = (int)(3.8 + 5.2);
    printf("a=%d,b=%d,c=%d\n", a, b, c);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

结果是

9,8,9
Run Code Online (Sandbox Code Playgroud)

我认为9,9,9是正确的输出,请告诉我,为什么.

c

2
推荐指数
1
解决办法
90
查看次数

标签 统计

c ×1