int findMax(int*sums){
int t = 0;
int max = sums[0];
while (sums[t] != '\0'){
printf("current max: %d %d\n", max, sums[t]);
if (sums[t] > max ){
max = sums[t];
}
t ++;
}
return max;
}
Run Code Online (Sandbox Code Playgroud)
这输出:
current max: 7 7
current max: 7 4
current max: 7 2
Run Code Online (Sandbox Code Playgroud)
它忽略了列表的其余部分sums.我认为这是因为下一个元素sums是0.但我不明白为什么它会被0视为'\0'(null).