0
Can anyone tell me the logic of this expression?
x += ? and how I should complete it if I want a increment by 1?
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;
0
isn't the same if we write it like x++ ?
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.
0
x=x+1
- 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.