=运算符在三个整数上使用两次时会做什么? [英] What does the = operator do when used twice on three integers?

查看:139
本文介绍了=运算符在三个整数上使用两次时会做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是做什么的?

int x = 1;
int y = 2;
int z = 3;
x = y = z;

我在一些开源项目中遇到过多种类型的东西,并且一直很困惑被他们。通过它们我的意思是=运算符在三个整数上使用两次,即 x = y = z; 。我需要了解这一点。谢谢!

I have come across multiple of this type of thing in a few open source projects and have always been confused by them. By them I mean the = operator being used twice on three integers i.e. x = y = z;. I need to understand this. Thanks!

推荐答案

运营商 = 评估右侧并分配结果是左侧的变量。表达式返回此值。

The operator = evaluates the right hand side and assigns the result to the variable on the left hand side. The expression returns this value.

为此,评估从右向左进行:

For this to work, evaluation proceeds from right to left:

x = (y = z);

y 变为3,返回的值是因此, x 也被分配了3个。

y becomes 3 and the value returned is 3. Thus, x is assigned 3 as well.

这篇关于=运算符在三个整数上使用两次时会做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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