小编Kar*_*och的帖子

当数组值为零而非空时,c循环停止

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.我认为这是因为下一个元素sums0.但我不明白为什么它会被0视为'\0'(null).

c arrays int max while-loop

5
推荐指数
1
解决办法
4718
查看次数

标签 统计

arrays ×1

c ×1

int ×1

max ×1

while-loop ×1