[*p++
解析为*(p++)
。
p++
的值为p
(并且副作用正在增加p
),所以*p++
的值与*p
相同。
除了副作用,*p
和*p++
相同。
与整数完全相同的事情:
int n = 6;
printf("%d\n", 7 * n);
printf("%d\n", 7 * n++); // except for the side-effect same value as above
在p ++中,因为++出现在p的[[after中,所以它表示后递增。这意味着,如果要使用p执行某些任务,则将使用值p,并且仅在完成该任务后才递增p。以下示例:
#include<stdio.h>
int main() {
int a, b;
a = 19;
b = 10;
if (a++ == 19) // 19 == 19. Checks out. // -------------------
// now that the line in which a++ appreared has
// finished executing, the post increment comes into play
// and a becomes 20
printf("%d\n", a); // 20 is printed
if (++b == 10) // 11 != 10. Code inside curly braces of if statement
// is not executed
printf("%d\n", b); // nothing is printed
// final output at the console
// 20 is printed
return 0;
}
因此,在您的情况下,首先将指针p
原样使用并取消引用。只有在该行完成执行后,++
才会起作用,并增加p
中存储的地址。