In C,
In the code below, I just want to be 100% sure that I understand the difference between statements (A) and (B):
void try_this(char *p, char *q)
{
const char* constptr = p; // (A)
char* const constptr2 = p; // (B)
}
(A) means that the data being pointed TO is constant
(B) means that the POINTER (address) is constant.
Now assuming that's the case, I could use some clarification on (A):
Suppose p was passed into the above function as "HELLO"
Suppose q was passed into the above function as "GOODBYE"
constptr points to the beginning of "HELLO".
I cannot say *constptr = 'J' because of the nature of the const.
But I can say
constptr = q; // now it will point to "GOODBYE"
(is this legal???.....)
Thanks
Steve
Start Free Trial