Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Q on complex assignment operators

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i %= 4 ==> 2
j<<= 2 ==> 12
k-=j ==> -5
p+=k ==> 25
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic