Consider the following case 1:
const int n = 5; int* p = &n; This is invalid, because &n is of type cont int* and p is of type int * (type mismatch error).
Now, consider this case 2:
int k = 4; int *const p = &k; This case compiles successfully, without any error. Clearly, p is of type int * const and &k is of type int *. In this case, there is a type mismatch, but it is valid.
Question : Why is the second case valid, even though there is a type mismatch?
constis only a promise not to modify the object via that pointer/reference. It does not mean that the object is unmodifiable. 2.int *constis a constant pointer (the pointer cannot be reassigned to point to something else), not a pointer toconst.const int n = 5; int *const p = &n;is legal? No. It does matter where const is. Constant pointer to int. Of course you can initialize a constant with a gvalue