C ++中的常量char *

时间:2014-06-26 17:05:00

标签: c++ pointers char

你能帮我澄清一下这条指令失败的原因吗?:

char * p = "string";
p[0] = 'a';

我在http://c-faq.com/decl/strlitinit.html中读到了一个字符串文字......

turns into an unnamed, static array of characters,
and this unnamed array may be stored in read-only memory

,这在http://www.cplusplus.com/doc/tutorial/pointers

String literals are arrays of the proper array type to contain all
its characters plus the terminating null-character, with each of the
elements being of type const char

这对我来说并不完全清楚:

  1. 两个概念都指的是同一个东西?

  2. 如果没有,哪一个是正确的?

  3. 每个常量都存储在只读存储器中吗?

  4. 非常感谢你。

0 个答案:

没有答案