#include <stdio.h>
int main(int argc, const char *argv[])
{
const char *s[] = {"a", "b", "c", NULL};
const char **p = s;
while (*p != NULL) {
printf("string = %s\n", *p);
(*p)++;
}
return 0;
}
我想遍历字符串数组并打印字符串 util 出现的 NULL 标记。 但是,它会生成一条由信号 SIGSEGV(地址边界错误)终止的消息。 谁能告诉我为什么?
最佳答案
(*p)++;
应该是:
p++;
这就是你正在做的事情:
p --> * --> "a"
| ^ incrementing this
checking this for null
您递增了错误的指针。
关于c - 遍历c中的字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24342062/