Reputation: 41
I encountered code similiar to the following in a c++, and I am unsure exactly what it does.
*x++ = *y++;
x
and y
are references to uint32
s.
I understand that ++
is the post-increment operator, and *
dereferences, but am still unsure of exactly what this does.
Upvotes: 4
Views: 54
Reputation: 84579
C++ Standard - 7.6.1.6 Increment and decrement expr.post.incr
Your expression *x++ = *y++;
applies the postfix operator ++
to each of the pointers x
and y
after the assignment from *x = *y;
occurs. Essentially the value of each operand is its value before any increment is applied. The increment is applied after the value computation.
The standard language is:
1 The value of a postfix
++
expression is the value of its operand.[Note 1: The value obtained is a copy of the original value. — end note]
The operand shall be a modifiable lvalue. ... The value of the operand object is modified (defns.access) by adding 1 to it. The value computation of the ++ expression is sequenced before the modification of the operand object. ...
2 The operand of postfix
--
is decremented analogously to the postfix++
operator.
7.6.1.6 Increment and decrement - expr.post.incr
The equivalent section in the C-Standard is 6.5.2.4 Postfix increment and decrement operators
Let me know if you have any further questions.
Upvotes: 5