Pointer to const object and const pointer,
1. A pointer to a constant object that means that the contents of the object pointed to by the pointer cannot be changed (cannot be assigned by pointer).
2. Constant pointer, meaning that the pointer content cannot be changed, pointing to object A cannot be changed to point to object B (pointers cannot be pointed elsewhere).
(Simply put, the const is near, which cannot change.) )
Pointer to const OBJECT:CONST double *cptr; Cptr is a constconst double pi = 3.14;double *ptr =π//error:ptr are a plain pointerconst do Uble *cptr =π//Ok:cptr is a pointer to constconst int universe = 42;const void *CPV = &universe; OK:CPV is constvoid *PV = &universe; Error:universe is constconst pointer:int errnumb = 0;int *const Curerr = &errNumb; Curerr is a constant pointercurerr = Curerr; Error:curerr is const
There's a more disgusting, const pointer to a const object
A constant pointer to a constant object, and a two (pointer and object) cannot be changed, both of which are const.
Const double PI = 3.14159;//pi_ptr is const and points to a const objectconst double *const pi_ptr =π
C + + array and pointer