aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Q on complex assignment operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Q on complex assignment operators" Watch "Q on complex assignment operators" New topic
Author

Q on complex assignment operators

Sumithab Baskaran
Ranch Hand

Joined: Oct 29, 2004
Posts: 52
This question is from whizlabs practice exam.

Check this out:
int i=10, j=3, k=7;
int p=30;
p += k -= j <<= i %= 4
What are the values of i,j,k,p?

This is how I interpret it: From right to left
p += (k -= (j <<= (i %= 4)))
Is this right?
1) (i %= 4) evaluates to 2 so i=2
2) (j <<= (i %= 4)) how do u evaluate j?? What does the <<= operator do?
Thanks
Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
i %= 4 ==> 2
j<<= 2 ==> 12
k-=j ==> -5
p+=k ==> 25


"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
p += (k -= (j <<= (i %= 4)))
Is this right?

yes
1) (i %= 4) evaluates to 2 so i=2

yes
2) (j <<= (i %= 4)) how do u evaluate j?? What does the <<= operator do?

shift the bits in j to the left i%4 places


Mike Gershman
SCJP 1.4, SCWCD in process
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Q on complex assignment operators