请解释为什么这段代码不起作用.. [英] Pls explain why this code is not going to work..
本文介绍了请解释为什么这段代码不起作用..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
%f不是double的格式说明符吗?我已经看过几次了......请解释........................
我尝试过:
Is %f not a format specifier for double? I have seen a couple of times that it is..please Explain........................
What I have tried:
#include<stdio.h>
#include<conio.h>
void main()
{
double d;
scanf("%f",&d);
printf("%f",d);
getch();
}
推荐答案
%f是float的格式代码,而不是double。由于double是浮点数的两倍,当你将浮点值读入内存中时,你获得的值是不正确的。
请尝试%lf。
%f is the format code for a float, not a double. Since a double is twice the size of a float, when you read a float value into the memory for a double, the value you get is not correct.
Try %lf instead.
这篇关于请解释为什么这段代码不起作用..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文