aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes operator precedence and arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "operator precedence and arrays" Watch "operator precedence and arrays" New topic
Author

operator precedence and arrays

preeti khane
Ranch Hand

Joined: Mar 12, 2003
Posts: 93


Can someone explain what's happening at line 7
Praveen Kumar Mathaley
Ranch Hand

Joined: Apr 14, 2003
Posts: 45
System.out.println(a[(a=b)[3]]);
let's consider how it's interpreted.
processing of the statement start from left to right
(a=b) get's evaluated which
assigns a to the reference held by b
this means now 'a' is pointing to array {0,1,2,3}
now the computation would be a[a[3] but here lies the trick, the outer 'a' reference was held before evaluating the argument. so the outer reference prints the 4th element of the array {11,12,13,14)
try inserting the line System.out.println(a[3]) at the end, it will print 3!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: operator precedence and arrays
 
Similar Threads
doubt in output of the program
Arrays - puzzling question?
StringBuffer
Runtime Error
Reg Arrays