c 语言中 用 %d输出double型数据;%f输出int型数据

 

001、 %f输出int型数据,其值为0.

[root@PC1 test]# ls
test.c 
[root@PC1 test]# cat test.c              ## 测试程序
#include <stdio.h>

int main(void)
{
        int i = 10;

        printf("i = %f\n", i);        // %f输出int型数据

        return 0;
}
[root@PC1 test]# gcc test.c -o kkk
[root@PC1 test]# ls
kkk  test.c
[root@PC1 test]# ./kkk
i = 0.000000

。 

 

002、%d输出double型数据

 

[root@PC1 test]# ls
test.c
[root@PC1 test]# cat test.c             ## 测试程序
#include <stdio.h>

int main(void)

{
        double i = 5.5;

        printf("i = %d\n", i);         // %d输出double型数据

        return 0;
}
[root@PC1 test]# gcc test.c -o kkk
[root@PC1 test]# ls
kkk  test.c
[root@PC1 test]# ./kkk                  ## 其返回值是一个不规则值
i = 1663286184

 

 。

 

posted @ 2024-07-28 20:23  小鲨鱼2018  阅读(2)  评论(0编辑  收藏  举报