输出预测无法理解while语句

0 c loops while-loop output

我正在寻找这个问题的解释。我看不懂while部分,为什么会打印6。

#include <stdio.h>
#include<stdlib.h>

int main() 
{
    int array[] = {1, 2, 4, 0, 4, 0, 3};
    int *p, sum = 0;

    p = &array[0];

    while (*p++)
        sum += *p;

    printf("%d\n", sum);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Jab*_*cky 5

这是while循环的一种更具可读性的形式:

while (*p != 0)
{
  p = p + 1;   // you can put "p++;" here, which has the same effect
  sum += *p;
}
Run Code Online (Sandbox Code Playgroud)

现在,您应该自己理解。