I don't understand something here. In the following code I have defined an integer and a constant integer.
I can have a constant pointer (int* const) point to an integer. See the fourth line of code.
The same constant pointer (int* const) can not point to a constant integer. See the fifth line.
A constant pointer to a const (const int* const) can point to a constant integer. That's what I would expect.
However, the same (const int* const) pointer is allowed to point to a non constant integer. See the last line. Why or how is this possible?
int const constVar = 42;
int variable = 11;
int* const constPointer1 = &variable;
int* const constPointer2 = &constVar; // not allowed
const int* const constPointer3 = &constVar; // perfectly ok
const int* const constPointer4 = &variable; // also ok, but why?