What is associativity for an operator and why is it important?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For operators, associativity means that when the same operator appears in a row, then which operator occurence we apply first. In the following, let
Qbe the operatorIf
Qis left associative, then it evaluates asAnd if it is right associative, then it evaluates as
It’s important, since it changes the meaning of an expression. Consider the division operator with integer arithmetic, which is left associative
If it were right associative, it would evaluate to an undefined expression, since you would divide by zero