0

Can you help me to clarify why this instruction fails?:

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

I have read in http://c-faq.com/decl/strlitinit.html that a string literal...

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

and this in 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

This is not completely clear for me:

  1. both concepts refer to the same thing?

  2. if not, which one is correct?

  3. is every constant stored in read-only memory?

Thank you very much in advance.

Mark Renton
  • 101
  • 2
  • 7

0 Answers0