read the example public class operat{ public static void main(String args[]){ int i=0; int []a={3,7}; a[i]=i=9; System.out.println(i + ""+a[0]+""+a[1]); } } since = opearator is right associative,it shud move from right to left and give arrayindex out of bound.But it does not!!Kindly explain
Hi Puneet Well, i try to explain Any exprseeion is sloved in two steps. They are Step 1) First Recognise ALL the oprands in expression (moving from left to right) Step 2) Then do the Operations (considering their prcedence and associativity) So going through these Steps on ur expression, we have Step 1) Recognise all operands moving from left to right So, we have three operands Operand # 1 = a[0] (a refernce to the 1st elemnet of array a) Operand # 2 = i (simply a refernce to the variable) Operand # 3 = 9 ( a constant value) Step 2) Now the expression becomes a[0]=i=9 And the operation of assignment is done. Thus giving NO out of Bound error I hope this will help u Bye
Well, I serached more and found the following justification The precedence of [] is higher than = So, [] will have to be solved first in the expression