If changed:
Then it runs correctly. After thinking about it, I finally found the answer by checking the information in the morning.
I made a test program and cut a graph. The answer is as follows:
All the answers are on the graph.
Summary:
1. char * p = "hello"; // determine the content of the string during compilation.
Char q [] = "hello"; // determine the string content at runtime
Where, p Stores the string address, and q stores the string itself. Therefore, p cannot be modified after initialization.
In terms of speed, it is obvious that the second method is faster than the first one.
2. C language program memory allocation, which has the following areas:
Like char * p = "hello"; strings defined in this way are placed in the text constant area. Therefore, it cannot be modified after definition.
Ps: url: http://hi.baidu.com/elnydtrjwrafkmr/item/49d767db2ad476f192a974d5
Ps:
String str = 2 + "abcdef"; // (here, the + time arithmetic operator is not the one after the overload)
Cout <"The str7 is \" "<str7 <" \ "" <endl;
The answer is The str7 is "cdef ".
Analysis: All constants in the program exist in the constant area. "Abcdef" is stored in the text constant area and has a relative offset address. Is a part of the constant area. If a value is added to the string operation, the result is equivalent to the original offset, the returned string is a new string starting from the new offset address to '\ 0.