Possible Duplicate:
Java - Order of Operations - Using Two Assignment Operators in a Single Line
If we assign a variable a value in a chain like the following,
int x=10, y=15;
int z=x=y;
System.out.println(x+" : "+y+" : "+z);
then the value of all three variables x, y and z becomes 15.
I however don't understand the following phenomenon with an array.
int array[]={10, 20, 30, 40, 50};
int i = 4;
array[i] = i = 0;
System.out.println(array[0]+" : "+array[1]+" : "+array[2]+" : "+array[3]+" : "+array[4]);
It outputs 10 : 20 : 30 : 40 : 0. It replaces the value of the last element which is array[4] with 0.
Regarding previous assignment statement - int z=x=y;, I expect the value of the first element means array[0] to be replaced with 0. Why is it not the case? It's simple but I can't figure it out. Could you please explain?
By the way, this assignment statement array[i] = i = 0; is dummy and it has no value of its own in this code and should no longer be used but I just wanted to know how thing actually works in this case.