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?