Hello, I am working through the C++ Primer book and have come upon the code snippet that I have pasted below. Specifically this is dealing with const as it relates to pointers.
So you will know where I am starting from. The book states, "We use the term top-level const to indicate that the pointer itself is a const. When a pointer can point to a const object, we refer to that const as a low level const.
1 2 3 4 5 6
int i = 0;
int *const p1 = &i; // we can't change the value of p1; const is top-level
constint ci = 42; // we cannot change ci; const is top-level
constint *p2 = &ci; // we can change p2; const is low-level
constint *const p3 = p2; // right most const is top-level, left-most is not
constint &r = ci; // const in reference type is always low-level
I'm confused about the 4th line of code. It says that we can change p2, const is low-level. As I understand this, what it is saying is that the pointer (p2) can be changed to point to something else but the item that p2 points to can't be changed. Is this correct? Otherwise what is the const referring to at the beginning of the line? Thanks!