I found this text (source: https://education.cppinstitute.org/) and I'm trying to understand the second instruction.
Can you answer the question of what distinguishes these two instructions?
c = *p++;
and
c = (*p)++;
We can explain: the first assignment is as if the following two disjoint instructions have been performed;
c = *p;
p++;
In other words, the character pointed to by p
is copied to the c
variable; then, p
is increased and points to the next element of the array.
The second assignment is performed as follows:
c = *p;
string[1]++;
The p
pointer is not changed and still points to the second element of the array, and only this element is increased by 1.
What I don't understand is why it is not incremented when the =
operator has less priority than the ++
operator.