char a[] = "string literal"; char *p = "string literal";
我的程序崩溃了如果我尝试赋一个新值给p[i]。
A: 一个字符串字面值(C源代码中一个双引号串的正式术语)能通过两种稍微有些不同的方式被使用:
一些编译器有一个控制是否字符串字面值可写的开关选项(用于编译旧代码),一些可能有导致字符串字面值被正式作为const char数组的选项(为了更好的发现错误)。
同时参见问答1.31、6.1、6.2、6.8和11.8b。
参考:K&R2 Sec. 5.5 p. 104
ISO Sec. 6.1.4, Sec. 6.5.7
Rationale Sec. 3.1.4
H&S Sec. 2.7.4 pp. 31-2
(This Chinese translation isn't confirmed by the author, and it isn't for profits.)
Translator : jhlicc@gmai1.c0m
Origin : http://www.c-faq.com/decl/strlitinit.html