The associativity of which of the following operators is Left to Right, in C++ ?
2017
The associativity of which of the following operators is Left to Right, in C++ ?
- A.
Unary Operator
- B.
Logical not
- C.
Array element access
- D.
addressof
Attempted by 230 students.
Show answer & explanation
Correct answer: C
Answer: Array element access ([]) has left-to-right associativity in C++.
Explanation:
Array element access ([]): left-to-right associativity. Example: in the expression arr[i][j], grouping is (arr[i])[j], so the leftmost subscript is applied first.
Unary operators (for example, prefix ++, unary +/-, logical not, and address-of &): right-to-left associativity. When multiple unary operators appear, they are grouped from right to left.
Summary: Choose array element access as the operator whose associativity is left-to-right; the other listed operators are unary and use right-to-left associativity.
A video solution is available for this question — log in and enroll to watch it.