[英]Why does the following code work? I was hoping it would produce an error but it dosen't
以下代码中x的值是什么:
int x=15;
x %= x++ + +x - 3
请解释原因。
为什么它没有给出+x
或之前的多余+
语法错误?
您可以将代码分成以下部分,以了解其工作原理:
int x = 15;
int y = x++ + +x;
System.out.println(y); //result: 31 (x = 15, then incremation so it is 15 + 16)
System.out.println(x); //result: 16 because of previous incrementation
y = y - 3;
System.out.println(y); //result: 31 - 3 = 28
x %= y;
System.out.println(x); //result: 16 % 28 = 16
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.