First note that when the int array is created, each element is initialized to zero.
Basically, in a
simple assignment, the left-hand operand is evaluated
first to figure out exactly where the value of the right-hand expression should be assigned -- for example, a variable or a particular index of an array. In this case, we have...
int b = 0;
a[a[b]] = ...
Here, a[b] is a[0], which is 0. So a[a[b]] is also a[0].
And the line a[a[b]] = a[b] = b = 2 essentially becomes a[0] = (a[0] = (b=2)). So the value 2 is assigned to the variable b, which is assigned to a[0], which is assigned to a[0].
Therefore, a[0] is 2, while a[1] through a[9] are all zeros.