Skip to main content
1 of 2
bup
  • 61
  • 1
  • 1
a[b] = b = 0; 
  1. array indexing operator has higher precedence then assignment operator (see this answer):

    (a[b]) = b = 0;

  2. According to 15.26. Assignment Operators of JLS

There are 12 assignment operators; all are syntactically right-associative (they group right-to-left). Thus, a=b=c means a=(b=c), which assigns the value of c to b and then assigns the value of b to a.

(a[b]) = (b=0); 
  1. According to 15.7. Evaluation Order of JLS

The Java programming language guarantees that the operands of operators appear to be evaluated in a specific evaluation order, namely, from left to right.

and

The left-hand operand of a binary operator appears to be fully evaluated before any part of the right-hand operand is evaluated.

So:

a) (a[b]) evaluated first to a[1]

b) then (b=0) evaluated to 0

c) (a[1] = 0) evaluated last

bup
  • 61
  • 1
  • 1