A constant pointer, a center of gravity point at the back, it is a pointer, it points to a constant. The content of the address it points to cannot be modified to prevent errors such as modifying constants that occur when the pointer is mistakenly manipulated.
The pointer constant, the center of Gravity Point in the back, it must first be a constant, and then it is a pointer. The system cannot modify the address pointed to by the pointer constant, which means that the address pointed to by the pointer is fixed once it is initialized. However, the contents of the address it points to can be changed.
(1) char* const P1;
(2) Char const* p2;
(3) const char* p3;
(4) const char* const P4;
Analysis of the above four statements: in fact, only need to see the const distance which is near, which is to modify which.
(1), the const is used to decorate the P1 pointer itself, that is, the pointer itself is a constant, but the P1 point can be modified;
(2), the const is used to modify the pointer pointing to the variable, that is, the pointer p2 the content pointed to must be constant, cannot be modified;
(3) the same as (2);
(4), the content pointed to by the previous const modifier pointer, the next const-decorated pointer itself, that is, the pointer P4 itself is a constant, and the content it points to must be constant, cannot be modified.
Therefore, p1 is a pointer constant;
P2,P3 is a constant pointer;
The P4 both accounted for.
Constant pointer and pointer constants