Following is the test code:
int main()
{
int a = 3;
int b = 4;
a = a + b - (b = a);
cout << \"a :\" << a << \" \" <<
a = b + a - a;
is just written as
a = b + a - (b = a)
------>> (exp 1)
The following three results same as (exp 1)
a = (b + a - (b = a));
a = ((b + a) - (b = a));
a = (b + a) - (b = a);
Observations +, - operators has got same precedence and also left to right associativity Hence 'b+a' gets executed first and then 'a' value gets assigned to 'b' before subtraction
Now observe the following When a = 10 and b = 20;
a = (b = a) - b + a;
=======> a = 10; b = 10
a = ((b = a) - b + a);
=======> a = 10; b = 10
a = ((b = a) - (b + a));
=======> a = -10; b = 10
From the above expressions its clear that even if innermost parenthesis gets executed first the associativity is followed first and then the precedence
Note:
To avoid confusion between the precedence of outer and inner parenthesis
Consider the following expression
a = (b + a - (b = a))
=====> Actual Result => a = 20, b = 10;
would have been a = 10, b = 10; (if precedence is primary when compared to associativity)
Thus by the above example we can say that associativity is primary when compared to precedence