• Post Reply Bookmark Topic Watch Topic
  • New Topic

Arrays: Unable to understand this question  RSS feed

 
Priyavrat Kumar
Greenhorn
Posts: 27
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not able to understand this question.
Please help

 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
 
Junilu Lacar
Sheriff
Posts: 11165
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!