I saw the section of const in Expert C Programming and found that although I had spent time studying this problem, I still don't know it, so I recorded some of my ideas, for future reference.
The statement of const and pointer together has several different orders:
Const int * num;
Int const * num;
Int * const num;
Among them, the declaration of 1 and 2 is "the pointer refers to the object is read-only", and 3 refers to "the pointer itself is read-only ".
Why?
If int is taken away, the declaration of 1 and 2 is actually the same, both are const *, and the declaration of 3 is * Const.
* The operator is in the order of right-to-left union. In const *, const specifies (* num), and (* num) indicates the object to which the Pointer Points, is limited to read-only; In * const num, const directly limits num. Num is the pointer itself, so the pointer is limited to read-only.
In the final analysis, when you encounter a const pointer, enclose the parts of the const in parentheses to see whether it is an object or a pointer.