big*_*ato -1 c arrays string pointers
#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;
}
Run Code Online (Sandbox Code Playgroud)
我想遍历字符串数组并打印字符串util出来的NULL sentinal.然而,它通过信号SIGSEGV(地址边界错误)消息生成终止.谁能告诉我为什么?
(*p)++;
Run Code Online (Sandbox Code Playgroud)
应该只是:
p++;
Run Code Online (Sandbox Code Playgroud)
这是你在做什么:
p --> * --> "a"
| ^ incrementing this
checking this for null
Run Code Online (Sandbox Code Playgroud)
你正在递增错误的指针.