复杂的表达 [英] Complex Expression

查看:83
本文介绍了复杂的表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的笔友

我是Anwar,请解释这个表达式如何变成24岁

{

int a = 10 ;

a = ++ a + ++ a;

cout<< a;

}


这个程序在屏幕上显示24,所以我无法理解这个表达式请解释它如何变成24

Dear thescripts
I am Anwar, please explain this expression how it becomes 24

{
int a = 10 ;
a = ++a + ++a;
cout << a ;
}

this program shows 24 on the screen so i can''t understand this expression please explain it how it becomes 24

推荐答案

Preincrement ++的优先级高于+。这就是为什么你的表达式
Preincrement ++ has higher precedence than +. That''s why in your expression
展开 | 选择 < span class =codeDivider> | Wrap | 行号


它的内存,...

++时a遇到了,a的地址值被改变了..所以当在第二个++ a时,同一个地址被改为12 ..


所以当加法运算时,12 +12被评估..


如果错误请告诉我答案...
its a thing of memory,..
when ++a is encountered, the value in address of a is changed.. so when in second ++a, the same address is changed as 12..

so when addition is operated, 12+12 is evaluated..

if wrong pls tell me the answer...



亲爱的帖子

我是安华,请解释这个表达式如何变成24


{

int a = 10;

a = ++ a + ++ a;

cout<< a;

}


这个程序在屏幕上显示24,所以我无法理解这个表达,请解释它如何变成24
Dear thescripts
I am Anwar, please explain this expression how it becomes 24

{
int a = 10 ;
a = ++a + ++a;
cout << a ;
}

this program shows 24 on the screen so i can''t understand this expression please explain it how it becomes 24



如果我们将其作为更改写出来,我们会看到:

a = 10

++ a + + + a


a = 11

a + ++ a


a = 12

a + a等于24.


但如果你把它写成

a = ++(a + a)


你会得到21 {++(10 + 10)}


- Miles

If we write it out as a changes we''d see this:
a = 10
++a + ++a

a = 11
a + ++a

a = 12
a + a which equals 24.

but if you wrote it as
a = ++(a + a)

you''d get 21 { ++( 10 + 10 ) }

- Miles


这篇关于复杂的表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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