7 + c * - d / e
c = 5,d = -7,e = 11
有人可以解释为什么7 + x * - d / e在我预期时返回3.3636
它返回-8.7272它是什么
当我使用(7 + c)* - d / e
c = 5, d = -7, e = 11
Could someone explain why 7 + x * -- d / e returns 3.3636 when I expect
it to return -8.7272 which it does
when I use (7 + c) * -- d / e
Les Coover< lc ****** @ cox.net.spam>在消息中写道
新闻:去******************** @ news2.central.cox.net。 ..
Les Coover <lc******@cox.net.spam> wrote in message
news:Go********************@news2.central.cox.net. ..
c = 5,d = -7,e = 11
有人可以解释为什么7 + x * - d / e在I $ b $时返回3.3636 b
是'x'应该是''c''?如果没有,那么
是''x''? ''c'','d''和''e''有哪些类型?
期待它返回-8.7272它确实是什么
c = 5, d = -7, e = 11
Could someone explain why 7 + x * -- d / e returns 3.3636 when I
Is that ''x'' supposed to be ''c''? If not, what
is ''x''? What are the types of ''c'', ''d'', and ''e''?
expect
it to return -8.7272 which it does
when I use (7 + c) * -- d / e
读入你最喜欢的C教科书
运算符优先级。我不能告诉
肯定,因为你没有显示类型
的变量,但你也可能是
看到转换结果,导致
意外结果,例如整数除法
当你浮动时
点积分。
-Mike
Read in your favorite C textbook about
operator precedence. I can''t tell for
sure since you don''t show the types
of the variables, but you may also be
seeing the results of conversions, leading
to unexpected results, e.g. integer division
when you though you were getting floating
point division.
-Mike
Les Coover写道:
Les Coover wrote:
c = 5,d = -7,e = 11
有人可以解释为什么7 + x * - d / e返回3.3636当我希望它返回-8.7272时它会使用(7 + c)* - d / e
c = 5, d = -7, e = 11
Could someone explain why 7 + x * -- d / e returns 3.3636 when I expect
it to return -8.7272 which it does
when I use (7 + c) * -- d / e
因为你正确解析它:
#include< stdio.h>
int main(无效)
{
双c = 5,d = -7,e = 11;
printf( 7 + c * --d / e:%g \ n,7 + c * --d / e);
c = 5; d = -7; e = 11;
printf("(7 + c)* --d / e:%g \ n",(7 + c)* - d / e);
c = 5; d = -7; e = 11;
printf(7 +(c * --d)/ e:%g \ n,7 +(c * --d)/ e);
c = 5; d = -7; e = 11;
printf(7 + c *( - d / e):%g \ n,7 + c *( - d / e));
返回0;
}
7 + c * --d / e:3.36364
( 7 + c)* --d / e:-8.72727
7 +(c * --d)/ e:3.36364
7 + c *( - d / e):3.36364
-
Martin Ambuhl
Because you are parsing it incorrectly:
#include <stdio.h>
int main(void)
{
double c = 5, d = -7, e = 11;
printf("7 + c * --d / e: %g\n", 7 + c * --d / e);
c = 5; d = -7; e = 11;
printf("(7 + c) * --d / e: %g\n", (7 + c) * --d / e);
c = 5; d = -7; e = 11;
printf("7 + (c * --d) / e: %g\n", 7 + (c * --d) / e);
c = 5; d = -7; e = 11;
printf("7 + c * (--d / e): %g\n", 7 + c * (--d / e));
return 0;
}
7 + c * --d / e: 3.36364
(7 + c) * --d / e: -8.72727
7 + (c * --d) / e: 3.36364
7 + c * (--d / e): 3.36364
--
Martin Ambuhl
Les Coover写道:
Les Coover wrote:
float c = 5,d = -7,e = 11;
有人可以解释为什么7 + c * - d / e返回3.3636
7 + c * - d / e =(7 +(c *(( - d)/ e)))
当我希望它返回时-8.7272
我无法解释为什么*你*会期望的。
它在我使用时会发生(7 + c)* - d / e
float c = 5, d = -7, e = 11;
Could someone explain why 7 + c * -- d / e returns 3.3636
7 + c*--d/e = (7 + (c*((--d)/e)))
when I expect it to return -8.7272
I can''t explain why *you* would expect that.
which it does when I use (7 + c) * -- d / e