Both character arrays and character pointer variables can be used to store and operate strings, but there is a difference between the two. When using, you should pay attention to the following issues:
1) The string variable itself is a variable that holds the first address of the string. The string itself is stored in a contiguous memory space at the first address and ends with "s" as a string. Character arrays are composed of several array elements that can be used to hold the entire string.
2) How to assign values. A character array can only be assigned to individual elements, and a character array cannot be assigned a value in the following way.
For a character pointer variable, you can assign a value using the following method.
3) The character array consists of several elements, one character in each element, and the character pointer variable holds the address, not the string into the character pointer variable.
4) If a character array is defined, it is assigned a memory unit at compile time and it has a definite address. When defining a character pointer variable, assign a memory unit to the pointer variable, where you can put an address value. That is, the pointer variable can point to a character data, but if it is not assigned an address value, she does not specifically point to a certain character data, so this method is not advocated.
5) The value of the pointer variable can be changed, although the array name represents the address, but its value cannot be changed. You can use the subscript form to reference the characters in the specified string.
6) Use a pointer variable to point to a format string, which can be used instead of a format string in the printf function. It can also be implemented with a character array, but it cannot be assigned as a whole using an assignment statement. For example:
The difference between using a string pointer variable and a character array