• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Arrays: Unable to understand this question

 
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not able to understand this question.
Please help

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, what is the question? Second, please QuoteYourSources.


... but ... to do a little speculation... I will speculate that you are having an issue of how the arrays are dereferenced. Keep in mind that order of evaluation are left to right. So, the first array, reference by "a", is resolved to the original "a" array instance, before it is assigned to the "b" array instance later.

Henry
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 5 is the key piece here. The expression (a=b) is an assignment. It makes the variable a reference the array that b references. The value of that expression is b. Hence, (a=b)[3] evaluates to b[3] which evaluates to 0. The output of line 5 therefore is the value of a[0]. You need to figure out whether that is 1 or 2 based on an understanding of whether the outer reference to variable a evaluates to the first array or the second array. The JLS section on expressions and order of evaluation is what you'll need to understand to correctly predict the output.
 
Marshal
Posts: 79180
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can tell you exactly what that code would mean if you wrote it at work. It would mean you are very suddenly looking for a new job. The assignment inside () is specially intended to confuse.
reply
    Bookmark Topic Watch Topic
  • New Topic