The key is the precedence of the +=
and the ++
operator. The ++
has a higher precedence than the +=
(in fact, assignment operators have the second lowest precedence in C), so the operation
*p++
means dereference the pointer, then increment the pointer itself by 1 (as usually, according to the rules of pointer arithmetic, it's not necessarily one byte, but rather sizeof(*p)
regarding the resulting address). On the other hand,
*p += 1
means increment the value pointed to by the pointer by one (and do nothing with the pointer itself).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…