📜  什么是运算符的关联属性 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:49.890000             🧑  作者: Mango

代码示例1
Left Associative means we evaluate our expression from left to right

Right Associative means we evaluate our expression from right to left 
We know *, /, and % have same precedence, but as per associativity, answer may change:

For eg: We have expression: 4 * 8 / 2 % 5

Left associative:   (4 * 8) / 2 % 5 ==> (32 / 2) % 5 ==> 16 % 5 ==> 1

Right associative:  4 * 8 /(2 % 5) ==>  4 * ( 8 / 2) ==> 4 * 4 ==> 16