17
为什么在写入以字符串文字形式初始化的“ char * s”而不是“ char s []”时出现分段错误?
以下代码在第2行上收到段错误: char *str = "string"; str[0] = 'z'; // could be also written as *str = 'z' printf("%s\n", str); 尽管这很好用: char str[] = "string"; str[0] = 'z'; printf("%s\n", str); 经过MSVC和GCC测试。