Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在这里,我得到的 o/p 为“1”,但我的期望是“100”。为什么会这样?请阐明一些观点。谢谢!
int main() { cout << 100 / 10 / 10 << endl; }
对于具有相同优先级的算术运算符,从左到右进行评估。这就是为什么你得到 1 -
查看此优先表。
当运算符具有相同的优先级时,它们从左到右进行评估。
这是基本代数。
来自 TCPPL 第 4 版的第 257 页
一元运算符和赋值运算符是右结合的;所有其他人都是左关联的。例如,a=b=c 表示 a=(b=c) 而 a+b+c 表示 (a+b)+c