Precedence of an operator can be compared to as a rank. If different operators are given in an expression,
for eg: a+b*c;
Here + and * are the operators. By looking the precedence of the operator, the compiler will decide which operator will execute first. Here * operator has highest precedence than + operator. So * operator will be executed first and after that operator + will be ececuted. This is known as the precedence of an operator
Associativity means that when the same operator appears in a row, then to which direction the evaluation binds to.
for eg: let A be an operator and aAbAc be the expression .
if A is left assocoative, then it evaluates as,
(aAb)Ac . That means aAb will be evaluated first and then the result will be evaluates with c.
if A is right associative, then it evaluates as,
aA(bAc). That means bAc will be evaluated first and then the result will be evaluated with a
This is known as the associativity of operator.