什么是这个代码的输出为什么?

use*_*416 -1 c c++ printf pointers

我有一个C++函数,我知道会是什么,但为什么?

int c[5];
int* pc = c;

for (int i = 0; i < 5; i++)
{
    c[i] = i*2;
}
*pc++;
printf("%d\n", pc-c );
Run Code Online (Sandbox Code Playgroud)

rwo*_*ols 5

有很多垃圾代码正在进行中.这是印刷品唯一重要的东西:

int c[5];              // c is a pointer
int* pc = c;           // pc points to the same thing as c.
pc++;                  // pc now points to one-past-where-c-points-to
printf("%d\n", pc-c ); // will print the pointer differences. 1.
Run Code Online (Sandbox Code Playgroud)

注意

*pc++;
Run Code Online (Sandbox Code Playgroud)

实际意味着

*(pc++);
Run Code Online (Sandbox Code Playgroud)

这与...不同

(*pc)++;
Run Code Online (Sandbox Code Playgroud)

如有疑问,请始终使用括号.