0

Can anyone tell me the logic of this expression?

x += ? and how I should complete it if I want a increment by 1?

2nd Aug 2016, 4:05 PM
Gabriel Celis Maya
Gabriel Celis Maya - avatar
5 Answers
+ 4
it's x += 1; this code means the same as: x = x+1 So if x is for eg. 2, then it's like: x = x (2)+1 => x = 3; and the short Form is x += 1;
2nd Aug 2016, 5:09 PM
Kamil
Kamil - avatar
0
isn't the same if we write it like x++ ?
4th Aug 2016, 6:21 PM
Dragoș Nedelcu
Dragoș Nedelcu - avatar
0
x++ will apply if there is only one variable i.e. x, which needs to be incremented by 1. In case of two variables (x and y), the expession will be x=x+y or x+=y, x and y can take any values depending on user input or value determined in the previous section of the code whichever applicable.
8th Aug 2016, 2:38 AM
Apratim Mohan
Apratim Mohan - avatar
0
x=x+1
23rd Sep 2016, 5:02 PM
sagir
sagir - avatar
- 1
x+=y means x=x+y. It is a shorthand notation and it works for the other basic operators in the same way. eg. x-=y or x*=y.
2nd Aug 2016, 5:45 PM
Sumitabha Banerjee
Sumitabha Banerjee - avatar