int array = new int; int index = 0; array[index] = index = 3; // 1st element get assigned to 3, not the 4th element Can anyone explain me this, i thought the answer was array = 3. answer is array =3; but its wrong.
Hi Sai, This is just really an example showing operator precedence. In the line: array[index] = index = 3; the  operator has the highest precedence: Step 1: array = index = 3; Next we are just left with assignment operator which works from right to left: Step 2: array = (index = 3); Step 3: array = 3 Done with array = 3 and index = 3! Regards, Manfred.
Is it because of operator precedence ? I thought it is a case of Evaluation order and Assignment order rule. Evaluation order is from left to right; so array(index) get evaluated first, and at that time since index had a value 0 the first element of the array is picked up. Then because assignment order is from right to left, 3 is assigned to index first and then that value of index is assigned to array(0). Also, is  an operator ? I think it is not. Please correct me if I am confusing others with wrong understanding. Thanks.
JLS �3.11, and �3.12 list 'separators' and 'operators'. Eventhough () and  are called separators, they have high precedence over any operators. Because of that, they are always listed with operators in order of precedence in all books I have seen. Any how, because "" has the same highest precedence as "()", it is evaluated first.