Which among the following operator has the right to left associativity?
Which among the following operator has the right to left associativity?
Answer: D. Increment/Decrement — In programming, associativity determines the order in which operators of the same precedence are evaluated. Operators can be left-associative (evaluated from…
- A.
Arithmetic
- B.
logical
- C.
Relational
- D.
Increment/Decrement
Attempted by 1018 students.
Show answer & explanation
Correct answer: D
In programming, associativity determines the order in which operators of the same precedence are evaluated. Operators can be left-associative (evaluated from left to right) or right-associative (evaluated from right to left).
Arithmetic, logical, and relational operators are generally left-associative. However, the increment (++) and decrement (--) operators are unary and are right-associative. This means that in an expression with multiple increment/decrement operators, they are evaluated from right to left.
For example, in the expression ++x++ (if valid), the rightmost operator is evaluated first due to right associativity.
Thus, among the given options, only the increment/decrement operators have right-to-left associativity.