gpt4 book ai didi

Java - 括号和赋值

转载 作者:行者123 更新时间:2023-12-01 14:05:34 28 4
gpt4 key购买 nike

编码:

int r=1;
System.out.println(r + (r=2));

输出是:3。但我期望是4,因为我认为括号内的代码是先执行的?

最佳答案

Official Docs on Operators says

All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.



所以 +被评估 left-to-right , 其中赋值运算符被评估 right to left.

关于Java - 括号和赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17808093/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com