# Q on complex assignment operators

Sumithab Baskaran

Ranch Hand

Posts: 52

posted 12 years ago

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

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

Posts: 132