我遇到了一个问题,可归纳如下,
#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