C++ 運算子、優先順序和順序關聯性
C++ 語言包含所有 C 運算子,並且新增了數個新的運算子。 運算子指定要對一個或多個運算元執行的評估:
運算子優先順序指定作業在包含多個運算子的運算式中的順序。 運算子關聯性指定在包含多個有相同優先順序之運算子的運算式中,運算元與其左邊或右邊的運算元群組。 下表顯示 C++ 運算子的優先順序和順序關聯性 (從最高到最低優先順序)。 除非以括號明確強制其他關聯性,否則運算子的優先順序數字若相同,其優先順序即相等。
C++ 運算子的優先順序和順序關聯性
運算子描述 |
---|
Group 1 precedence, no associativity |
Group 2 precedence, left to right associativity |
Group 3 precedence, right to left associativity |
Group 4 precedence, left to right associativity |
Group 5 precedence, left to right associativity |
Group 6 precedence, left to right associativity |
Group 7 precedence, left to right associativity |
Group 8 precedence, left to right associativity |
Group 9 precedence, left to right associativity |
Group 10 precedence left to right associativity |
Group 11 precedence, left to right associativity |
Group 12 precedence, left to right associativity |
Group 13 precedence, left to right associativity |
Group 14 precedence, left to right associativity |
Group 15 precedence, right to left associativity |
Group 16 precedence, right to left associativity |
Group 17 precedence, right to left associativity |
Group 18 precedence, left to right associativity |