我正在学习 C,但我不知道如何表达这一点,但为什么在以下代码中取消注释第 11 行会破坏该程序?
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("argc: %d\n", argc);
char *states[] = {};
int i = 0;
while(i < argc) {
printf("arg %d: %s\n", i, argv[i]);
//states[i] = "test";
i++;
}
return 0;
}
当我取消注释这一行并运行程序时,我得到:
greggery@Lubu:~/code$ ./myprog aaa bbb ccc
argc: 4
arg 0: ./lc
arg 1: aaa
为什么要states[i] = "test";
打破while
循环?当我将其注释掉时,我会看到打印的所有论点。