Constant pointer and pointer constant
In this way, the first two words are usually modifiers, and the Central Word is the last word. The constant pointer and pointer constant here are the same.
Constant pointer, expressed as "a constant Pointer". It should be a pointer first.
A pointer constant, expressed as a constant of a pointer. It should first be a constant.
Constant pointer. What kind of pointer is it? It is a pointer to a constant, that is, we define a constant, such as const Int.
A = 7; then we can define a constant pointer to point to it const int * P = & A; it can also be divided into two steps, namely, const int * P;
P = & A; So what does it do? First of all, let's talk about the attributes of constants, because our pointers point to constants. The difference between constants and variables is that we cannot proceed with their contents.
The operation, specifically, is to modify, and what is our pointer, its content is itself an address, set the constant pointer to a constant, in order to prevent us from writingProgramAbnormal changes to pointer misoperations
If we modify the space pointed to by the constant pointer, the compilation system will prompt us with an error message. To sum up,A constant pointer is a pointer to a constant. The content of the address pointed to by the pointer cannot be modified.
A pointer constant is a constant first, and then a pointer. A constant cannot be modified. The pointer content is actually an address. A pointer constant is a constant whose content cannot be modified. That is, the content cannot be modified.
What is the content of the modified pointer? The pointer content is the address. In the end, you cannot modify the address pointed to by the pointer. It can only point to the address at the beginning of initialization. No
It can point to other places, just like the array name of an array. It is a fixed pointer and cannot be moved. For example, you can use P ++; the system prompts an error. However, it just cannot be modified.
But the content in the point can be replaced, which is completely different from the constant pointer mentioned above. To sum up,A pointer constant is a constant of a pointer. It is a pointer that cannot change the address, but can modify the content it points.By the way, I forgot to talk about how to use it. For example, int A; int * const P = & A; you can also separate int A; int * const P; P = &;
Of course, you can also define a pointer constant pointing to a constant, so that we can combine the above two values to indicate the following:
Const int A = 7; const int * const P = &;