C ++ pointer and constants pointer

These two concepts are easily confused, even veterans, have vertigo when writing this blog, enhance memory ...

 

Constant pointer: a pointer, and it is a constant whose value can not be changed;

char * const p1 = "Hello!"; // must be defined at initialization time, because it is a constant p1 = "NiHao!"; // error, does not allow for constant values

 

Constant pointer: a pointer to an object and it is a constant (not allowed to change), but the value of the pointer itself may be varied;

const char * p2 = "Hello!"; // can not initialize p2 = "NiHao!"; // correct

Guess you like

Origin www.cnblogs.com/isky0824/p/12096634.html