sum=(++i)+(++i)+(++i);

guozhennan123 2010-04-23 01:48:50
如题,这个是怎么计算的,为什么dev c++得22,我是学C#的,用那个是21,还有,谭浩强老实的书里为什么得24,知道的说下,谢谢了先
...全文
127 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
hzy694358 2010-04-23
  • 打赏
  • 举报
回复
未定义的东西,讨论也没多大的意义,不要这样用
天亮后说晚安 2010-04-23
  • 打赏
  • 举报
回复
呵呵
[Quote=引用 1 楼 pengzhixi 的回复:]
oh 月经贴变日经贴了。
[/Quote]
机智的呆呆 2010-04-23
  • 打赏
  • 举报
回复
What's the value of i++ + i++?
It's undefined. Basically, in C and C++, if you read a variable twice in an expression where you also write it, the result is undefined. Don't do that. Another example is:

v[i] = i++;

Related example:

f(v[i],i++);

Here, the result is undefined because the order of evaluation of function arguments are undefined.

Having the order of evaluation undefined is claimed to yield better performing code. Compilers could warn about such examples, which are typically subtle bugs (or potential subtle bugs). I'm disappointed that after decades, most compilers still don't warn, leaving that job to specialized, separate, and underused tools.

无论 C 还是 C++,如果在同一个表达式中两次读取同一个变量,并且还对该变量进行写操作,那么结果就是未定义的
http://www2.research.att.com/~bs/bs_faq.html#working-on-now
jacey_48557 2010-04-23
  • 打赏
  • 举报
回复
据说 一个表达式最好不要出现对一个变量做多次变换,所以,这个问题据说是不用深入的!呵呵
guozhennan123 2010-04-23
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 taodm 的回复:]
呃,C#改C、C++真要命啊。
[/Quote]我不是改,只是想多学点啊,汗
guozhennan123 2010-04-23
  • 打赏
  • 举报
回复
不是的,i已经定义,是5
taodm 2010-04-23
  • 打赏
  • 举报
回复
呃,C#改C、C++真要命啊。
CCCCCCCCCCCCCCC 2010-04-23
  • 打赏
  • 举报
回复
标准里德未定义行为,依赖于具体编译器实现。

所以,不同编译器得到的结果可能是不同的。
某某9 2010-04-23
  • 打赏
  • 举报
回复
++i 的问题 很多 很多~~
jay1002008 2010-04-23
  • 打赏
  • 举报
回复
i是什么啊
mstlq 2010-04-23
  • 打赏
  • 举报
回复
pengzhixi 2010-04-23
  • 打赏
  • 举报
回复
oh 月经贴变日经贴了。

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧