Because of an interview question, I caught tan haoqiang's C LanguageProgramIn the design section, in the 240-page 10.22 examples, the character Pointer Points to a character, which can be accessed through a character array, using [], that is: char * A = "I love China ";
Printf ("The Sixth charcter is % C \ n", a [5]);
I suddenly wondered if I could use a character pointer to change the content that it points to, that is
In the vs2005 environment, "0xc0000005: Access conflict occurs when the write location is 0x00418bf0". If it is written as follows, it can be executed normally.
That is to say, it is allowed to "write" the character array through the character pointer, and the previous error is a running error, similar to the exc_bad_access error in xcode,The possible cause of speculation is that the character pointer is specified and the string is initialized directly. The memory space opened up is not the space on the stack.Const pointer errors. If "char * A =" I love China ";" is used, it is written as "const char * A =" I love China "; "To compile the" write operation"CodeYes, the compiler will report an error. Meanwhile, ask "char * A =" I
Love China ";" memory space.
Here is the answer to this question http://blog.csdn.net/defonds/article/details/6260429
"Therefore, the string literal in C ++ can be called a String constant, and the first address and each element address are the same as those in C. They are all address constant expressions.
the string literal is of the array type char [N] in C and const char [N] in C ++. in an expression, when an array is converted to a pointer, the corresponding equivalent pointer types are char * and const char *. Therefore, in C, char * P = "abcdef" is legal, but it is surprising that the preceding statement is also legal in C ++! It seems that a pointer to const char pointer is given a pointer to Char pointer, which seems to be in violation of the more CV-qualified principle for pointer conversion in C ++. In fact, there are two types of conversions in
C ++: one is based on the current context, and the other is based on the conversion from array to pointer, c ++ standard content: "