This question is difficult to say, but simple to say. When reading the following answer, remember that the pointer is a variable, and he has his own memory space, which stores the address of the variable he points to. Remember that the value of the pointer is the address.
1.const pointer means that the value of the pointer cannot be changed, that is, the value of the pointer is constant, assuming.
int * const p; Here's the point: const modifies p, and p is a pointer. We know that pointers are also variables, and memory will also allocate space for them. The address is put in it, so according to the attribute of const keyword, we can know that the value in pointer variable P cannot be changed. What's in the pointer variable? Yes, it's the address. Because it cannot be changed, we must initialize it when defining it, for example.
int i = 20
Constant p = &
Please do the following:
P = & ampI2 can't, because the value of p can't be changed, that is, it can't point to other addresses.
* p = 100; Correct, because he changed not the value of p, but the value of the variable he pointed to.
2. Pointer constant
form int const * p; Note that the positions of const keyword and int can be interchanged, which does not affect it. Note the position of * and const.
Key point: const modifies *p (this is the key point); We know that there is an address in P, so *p is the data in the address he points to, which is a value, not an address. What does that mean? Do you remember what const means? If a read-only variable is defined, its value cannot be changed. So the meaning of this sentence is: you can't change the value of *p:
Suppose the following statement
int I 1 = 30;
int i2 = 40
Constant int * pi = & ampi1;
Pi =&I2; /* Note that pi can reallocate a new memory location at any time.
Address */
I2 = 80/* Think about it: Can I use *pi = 80 instead? Of course not! */
printf("%d\n ",* pi); /* The output is 80 */
Semantic analysis:
Do you see it? The value of pi can be modified. That is, it can be redirected to another address.
Yes, but the value of i2 cannot be modified by *pi. I 1 and I 2 cannot be changed by *p, which means that the value of the variable he points to can be changed, but not by *p = 40.
It took me a long time to understand this problem, so the landlord will think about it again. You can experiment on the machine, which is even more remarkable ~ I wish you progress!