是[i] = i ++是否正确? [英] Is a[i] = i++ correct?

查看:54
本文介绍了是[i] = i ++是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想知道为什么是[i] = i ++;错误?人们说因为在编译过程中解析不同,所以它是

。请解释

技术上为什么它是错误的/行为未定义?


问候,

Jeniffer

Hi

I want to know why is a[i] = i++ ; wrong? People say that it is
because of different parsing during compilation.Please explain
technically why it is wrong/behaviour undefined?

Regards,
Jeniffer

推荐答案

jeniffer说:
jeniffer said:




我想知道为什么是[i] = i ++;错误?
Hi

I want to know why is a[i] = i++ ; wrong?



您认为它应该是什么意思?鉴于此代码:


int a [3] = {5,7,9};

i = 0;

a [ i] = i ++; / * bug * /


您认为某个[]的成员会更新,有什么价值?


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

What do you think it should mean? Given this code:

int a[3] = { 5, 7, 9 };
i = 0;
a[i] = i++; /* bug */

which member of a[] do you think will be updated, and to what value?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


12月28日,7:50 * pm,凝视...... @ xmission.xmission.com(Kenny McCormack)

写道:
On Dec 28, 7:50*pm, gaze...@xmission.xmission.com (Kenny McCormack)
wrote:

>

christian.bau< christian .... @ cbau.wanadoo.co.ukwrote:
>
christian.bau <christian....@cbau.wanadoo.co.ukwrote:

全世界的Java程序员都认为你完全错了。在

Java中,a [i] = i ++;定义了行为。从左到右评估表达式

。首先它评估左值a [i],然后是

右侧i ++。更改的数组元素由i的原始值确定。
Java programmers all over the world think you are completely wrong. In
Java, a [i] = i++; has defined behaviour. The expression is evaluated
from left to right. So first it evaluates the lvalue a [i], then the
right hand side i++. The array element changed is determined by the
original value of i.



嗯,这实际上并没有证明什么。 *这意味着Java

以这种方式定义它(可能是因为它更容易实现)和程序员接受它的
。 *这并不意味着它是可取的(也不是,因为这是不可取的)。


Well, that doesn''t actually prove anything. *What it means is that Java
defined it that way (probably because it was easier to implement) and
the programmers accepted it. *It doesn''t mean it is desirable (nor, of
course, does it mean it is undesirable).



您实际上认为Java中的任何内容都是按照定义的方式定义的

因为它更容易实现?说真的吗?

You actually think anything in Java is defined the way it is defined
because "it was easier to implement"? Seriously?


星期五,2007年12月28日20:17:30 +0000,Flash Gordon

< sp ** @ flash-gordon .me.ukwrote:
On Fri, 28 Dec 2007 20:17:30 +0000, Flash Gordon
<sp**@flash-gordon.me.ukwrote:

>我希望我已经纠正了你的错误观念。
>I hope I have corrected your misconceptions.



晚上好,Flash。


尊重,没有误解。只有部分

答案。我向Jeniffer提供了我认为需要的答案

而没有涉及到超出我所知问题的范围的大量细节。当然,我的看法可能是错误的。

Good evening, Flash.

Respectfully, there were no misconceptions. There were only partial
answers. I gave Jeniffer the answers that I thought were needed
without getting into a lot of detail that goes way beyond the scope of
my perception of the questions asked. Of course, my perception may
have been wrong.


这篇关于是[i] = i ++是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆