Relating to compound operaters | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Relating to compound operaters

does j+=a-b mean j=j+(a-b) or j=j+a-b

4th Apr 2018, 12:58 PM
divyam sureka
divyam sureka - avatar
3 Answers
+ 13
yes , case1 is true //still to eliminate any confusion in it , it is suggested to make use of brackets ()
4th Apr 2018, 1:44 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
j += a-b is both. due to the nature of addition, both are the same, so it doesn't matter. ;P But 'underneath the hood', Faisal is correct: it is j = j + (a - b). you can test that by testing j *= a - b, which does make a difference. u can see that it is j = j * (a - b). warning: i have not tested this so you need to assume we are all wrong until you test it yourself. ;P (But i have been a programmer for about 30 years.)
4th Apr 2018, 1:33 PM
Shawn Kovac
Shawn Kovac - avatar
i recommend against using parentheses like j += (a + b). it shows that u r an utter newbie, especially when the order does not matter. and it's just useless wasted extra symbols. in other words, using j += (a + b) is like using j = j + (a + b) when j = j + a + b is just the same *except easier to read*.
4th Apr 2018, 2:18 PM
Shawn Kovac
Shawn Kovac - avatar