小编Spa*_*ato的帖子

将printf移动到不同的行会产生不同的输出?(C)

在C中,当我移动此printf行时:printf("%f\n", 5 / 2);对于不同的行,其输出会发生变化.有任何想法吗?

下面是代码:

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


int main()
{   

    int a = 65;
    char c = (char)a;
    int m = 3.0/2;

    printf("%c\n", c);              
    printf("%f\n", (float)a);       
    printf("%f\n", 5.0 / 2);        
    printf("%f\n", 5 / 2.0);        
    printf("%f\n", (float)5 / 2);   
    printf("%f\n", 5 / (float)2); 
    printf("%f\n", (float)(5 / 2)); 
    printf("%f\n", 5.0 / 2);        
    printf("%d\n", m);              
    printf("%f\n", 5 / 2);


    system("PAUSE");
    return(0);
}
Run Code Online (Sandbox Code Playgroud)

继承人的产量:

A
65.000000
2.500000
2.500000
2.500000
2.500000
2.000000
2.500000
1
2.500000
Run Code Online (Sandbox Code Playgroud)

如果我移动printf("%f\n", 5 / 2);到第一行之一(在输出A的那一行和输出65.000000的那一行之间),它将打印0.000000(这是有意义的)而不是现在的2.500000.有任何想法吗?

c int printf casting

5
推荐指数
1
解决办法
338
查看次数

标签 统计

c ×1

casting ×1

int ×1

printf ×1