一个简单的查询 [英] a simple query
问题描述
printf("%d",(float)3/2);
输出为零...为什么不是1?即使你把它改成
printf("%d",(float)6/2);仍然输出为零
printf("%d",(float)3/2);
the output comes as zero...why not 1?even when u change it to
printf("%d",(float)6/2); still the output is zero
推荐答案
newbai写道:
newbai wrote:
printf ("%d",(float)3/2);
输出为零...为什么不是1?即使你把它更改为
printf (QUOT;%d",(浮点)6/2);仍然输出为零
printf("%d",(float)3/2);
the output comes as zero...why not 1?even when u change it to
printf("%d",(float)6/2); still the output is zero
Who''su?
%d告诉printf你传递一个整数值,但是你是通过一个浮动来
,那是'未定义的行为。
-
Ian Collins。
Who''s u?
%d is telling printf you are passing an integer value, but you are
passing a float, that''s undefined behaviour.
--
Ian Collins.
newbai写道:
newbai wrote:
printf("%d",(float)3/2);
输出为零...为什么不是1?即使你把它更改为
printf("%d",(float)6/2);仍然输出为零
printf("%d",(float)3/2);
the output comes as zero...why not 1?even when u change it to
printf("%d",(float)6/2); still the output is zero
%d格式说明符用于打印int参数。给printf
错误的类型会导致不明确的行为,即任何事情都可以发生
。
做:
printf("%d \ n",3/2);和printf(%d \ n,6/2);
或
printf("%f \ n,(浮动)3/2);和printf("%f\ n",(float)6/2);
The %d format specifier is for printing int arguments. Giving printf
the wrong type will cause undefined behaviour, i.e. anything can
happen.
Do:
printf("%d\n", 3/2); and printf("%d\n", 6/2);
or
printf("%f\n", (float)3/2); and printf("%f\n", (float)6/2);
newbai写道:
newbai wrote:
printf("%d",(float)3/2);
输出为零...为什么不是1?即使你把它改为
printf("%d",(float)6/2);仍然输出为零
printf("%d",(float)3/2);
the output comes as zero...why not 1?even when u change it to
printf("%d",(float)6/2); still the output is zero
%d想要一个int,表达式是一个浮点数,所有投注都关闭。
明天BOOM。明天总会有一个BOOM。
-
Chris" Ivanova" Dollin
你服务的对象是谁,你信任谁? /十字军/
%d wants an int, the expression is a float, all bets are off.
BOOM tomorrow. There''s always a BOOM tomorrow.
--
Chris "Ivanova" Dollin
"Who do you serve, and who do you trust?" /Crusade/
这篇关于一个简单的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!