The const pointer modifier is generally divided into the following four situations:
Int B = 500; const int * A = & B; // 1int const * A = & B; // 2int * const A = & B; // case 3 const int * const A = & B; // case 4
How is the difference?
If the const is on the left side of the asterisk, the const is used to modify the variable pointed to by the pointer, that is, the pointer points to a constant;
If const is on the right side of the asterisk, const modifies the pointer itself, that is, the pointer itself is a constant.
1. In case 1 and 2 are the same, the content pointed to by the pointer is a constant. In this case, the content cannot be changed.
For example
Int B = 500; const int * A = & B; // case 1 * A = 600; // Error
However, there are other ways to change the value of * A. One is to change the value of B, and the other is to point A to a = & C elsewhere.
In case 1 and 2, Initialization is not allowed. Although the pointer content is a constant, the pointer itself is not a constant.
2. Case 3: the pointer itself is a constant, and the pointer itself cannot be changed. The content pointed to by the pointer is not a constant.
Therefore, the definition must be initialized at the same time.
3. Case 4: the pointer itself and the content pointed to are constants.
Const modifier pointer