x = x * x vs. i = i ++ [英] x=x*x vs. i=i++

查看:100
本文介绍了x = x * x vs. i = i ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么i = i ++ undefined而x = x * x没关系?

why is i=i++ undefined while x=x*x is alright?

推荐答案



al.c ... @ gmail.com skrev:

al.c...@gmail.com skrev:
为什么i = i ++ undefined而x = x * x好吗?
why is i=i++ undefined while x=x*x is alright?




因为i = i ++包含对i的赋值。 x = x * x只包含一个

赋值给x。

当同一个变量有两个赋值而没有干预

sequenceproblem时,你遇到了麻烦。


彼得



Because i=i++ contains to assignments to i. x=x*x only contains one
assignment to x.
It is when the same variable has two assignments without an intervening
sequenceproblem, you get into troubles.

Peter


peter koch写道:
peter koch wrote:
al .c ... @ gmail.com skrev:
al.c...@gmail.com skrev:
为什么i = i ++ undefined而x = x * x好吗?
why is i=i++ undefined while x=x*x is alright?



因为i = i ++包含对i的赋值。 x = x * x只包含一个对x的赋值。
当同一个变量有两个赋值而没有介入的序列问题时,你会遇到麻烦。
彼得




出于好奇,i = ++ i怎么样?在这种情况下,至少看起来两个作业都做同样的事情。



Out of curiousity, what about i = ++i? In this case it at least seems
that both assignments do the same thing.


On 2006-03-21 21:04:16 - 0500,Mark P

< us **** @ fall2005REMOVE.fastmailCAPS.fm>说:
On 2006-03-21 21:04:16 -0500, Mark P
<us****@fall2005REMOVE.fastmailCAPS.fm> said:
peter koch写道:
peter koch wrote:
al.c ... @ gmail.com skrev:
al.c...@gmail.com skrev:
为什么i = i ++ undefined而x = x * x没关系?
why is i=i++ undefined while x=x*x is alright?



因为i = i ++包含对i的赋值。 x = x * x只包含一个对x的赋值。
当同一个变量有两个赋值而没有介入的序列问题时,你会遇到麻烦。
彼得



出于好奇,i = ++ i怎么样?在这种情况下,它至少看起来两个作业都做同样的事情。



Out of curiousity, what about i = ++i? In this case it at least seems
that both assignments do the same thing.




如果他们做同样的事情并不重要。 。事实上,其中两个是
,这两个行为都是未定义的行为。

-

Clark S. Cox,III
< a href =mailto:cl ******* @ gmail.com> cl ******* @ gmail.com



It doesn''t matter if they "do the same thing". The fact that there are
two of them makes it undefined behavior.
--
Clark S. Cox, III
cl*******@gmail.com


这篇关于x = x * x vs. i = i ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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