• 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

presedence problem

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The program below is giving the output 5 .
Now I know that the precedence of the [] operator is more than
the = operator but I have studied that one can change the order of precedence by applying small brackets ().Here alse we
have (arr=brr)[3] which means that arr=brr should be evaluated first and than [] operator and 3 should be the output.
Anyone plz clarify this.
class Testclass{
public static void main(String argv[]){
int arr[] = {2,3,4,5};
int brr[] = {1,3,4,3};
System.out.println(arr[(arr=brr)[3]]);
}
}
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And if you repeat the print it prints 3 the second time. What does this tell us? First, that we shouldn't do assignments in the middle of statements. Second, that the assignment doesn't actually take until the statement is complete.
------------------
Moderator of the Programmer Certification Forums
 
Die Fledermaus does not fear such a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic