When you have the statement:
*str++ = *end
Does the *str
get assigned the value of *end
or does it get incremented and then get assigned the value of *end
?
When you have the statement:
*str++ = *end
Does the *str
get assigned the value of *end
or does it get incremented and then get assigned the value of *end
?
As a post-increment operator, it first assigns *end
then points to new/incremented address of str
.
Logically, the expression evaluates to something like the following:
t0 = str;
t1 = *end;
str = str + 1;
*t0 = t1;
except that the exact sequence in which these operations occur is unspecified. The following sequences are also possible:
t0 = str;
str = str + 1;
t1 = *end;
*t0 = t1;
t0 = *end;
t1 = str;
*t1 = t0;
str = str + 1;
t0 = *end;
t1 = str;
str = str + 1;
*t1 = t0;
The one constant is that we're updating the location that str
points to before the increment.