P
pauldepstein
Take the following code snippet:
int x = 5;
int i = 7;
It's obvious to me what (x+=i )= 25; does and it's obvious to me what x
+=(i = 25); does.
However, (other than by trying it out), I'd have no idea which of the
two versions is meant by x+=i = 25;
Operator precedence doesn't seem to help because += and = have equal
precedence.
The order of the operators also isn't clear because = is right
associative.
My guess would have been "just go left to right" leading to (x+=i )=
25; However, experimentation shows this guess to be wrong. How
could this be known in advance?
Thanks,
Paul Epstein
int x = 5;
int i = 7;
It's obvious to me what (x+=i )= 25; does and it's obvious to me what x
+=(i = 25); does.
However, (other than by trying it out), I'd have no idea which of the
two versions is meant by x+=i = 25;
Operator precedence doesn't seem to help because += and = have equal
precedence.
The order of the operators also isn't clear because = is right
associative.
My guess would have been "just go left to right" leading to (x+=i )=
25; However, experimentation shows this guess to be wrong. How
could this be known in advance?
Thanks,
Paul Epstein