X+=Y Understanding

Slightly confused/stumped on the statements:

x+=y

and

x=+y

I know if I had, say, x++ or y++ that would mean whatever number x or y was it would be added by 1. Or if I had, say, x=y++ it would equal x=y - 1. Or also if I had x=++y it would equal x=y. But then again, I could have that all wrong too.
+= is the same as using x = x + y.
So if I had:
1
2
int x;
x = x + y;

That would be the same as:
1
2
int x;
x += y;


It is just a quicker way of doing this, like the increment operator (++)

Source: http://www.cplusplus.com/doc/tutorial/operators/
The first is just the same as saying x = x + y.
1
2
3
4
int x = 5;
iny y = 3;

x += y;  // x is now 8 


In the second, the plus is meaningless. It's just the same as x = y.

In prefix operations (++x), the value is incremented and then returned.
In postfix operations (x++), the value is returned then incremented.

1
2
3
4
5
int x = 0;
int y = 5;

x = y++;   // x = 5, y = 6
x = ++y;   // x = 7, y = 7; 
iHutch105 wrote:
In postfix operations (x++), the value is returned then incremented.
No, the value is copied, the original is incremented, and the copy is returned.
Ah! Thank y'all so much. That helped a lot.
Topic archived. No new replies allowed.