我正在寻找这个问题的解释。我看不懂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)
这是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)
现在,您应该自己理解。
| 归档时间: |
|
| 查看次数: |
54 次 |
| 最近记录: |