小编Sam*_*iyi的帖子

在C中缺少原型声明时,由于参数提升导致了奇怪的结果

我遇到了一个问题,可归纳如下,

#include <stdio.h>
int main()
{
        float f=23.45;
        printf("main: %f\n", f);
        t1(f);
/*    the result would be 
      main:23.450001 
      t1:2.000000    */          
}
void t1(float f)
{
        printf("t1: %f\n", f);
}
Run Code Online (Sandbox Code Playgroud)

我现在知道奇怪的行为是由于缺少原型声明而且因此提升了参数(float-> double?),我仍然无法弄清楚为什么结果是2.000000,所以有人能给出更详细的解释吗?我使用的是ubuntu10.04 gcc4.4.3

c types prototype

0
推荐指数
1
解决办法
119
查看次数

标签 统计

c ×1

prototype ×1

types ×1