可能重复:
Why do I get a segmentation fault when writing to a string?
我希望这个程序的输出是: ibjgsjfoet,但是我得到了一个分段错误。
#include <stdio.h>
int main()
{
    char *p="haifriends",*p1;
    p1=p;
    while(*p!='\0')
    ++*p++;
    printf("%s   %s",p,p1);
    return 0;
}发布于 2011-08-05 14:52:04
在同一个语句中使用两个自动增量是自找麻烦。别耍花招。编写您的代码,使其清晰和有表现力,您将获得更好的结果。
https://stackoverflow.com/questions/6958222
复制相似问题