Originally posted by Roopa Maheshkumar:
Hi... i have a little confusion here.
it seems to me that x[0] is 2 since x=y = {2,3,1,0}. Please clarify.
--------------------------------------------------
Please check if this explanation helps
if someone finds this incorrect, please correct me
Consider the left to right evaluation order in x[ (x=y)[3] ];
First the value of outermost x is evaluated which is reference to the first array {1,2,3,4}
Now the assigment is considered x=y which is reference to the second array { 2,3,1,0}
so value of (x=y)[3] is 0 which is the element at index 3 in the second array
Now the value is substituted ...so x[(x=y)[3]] becomes x[0]
Now the value of the x[0] as per the first array is 1
After the execution of this statement, the x and y references both point to the second array only.
To understand better, introduce a print statement
System.out.println( x[ 0] );
after the System.out.println( x[ (x=y)[3] ] );
That will give a different result 2..because now reference x also points to second array after the assignment..
[ May 31, 2008: Message edited by: Meena MeenakshiSubramanian ]