Why 1 is error and 2 is legal.
This code is taken from C++ primer 5th edition, There is not much detail on this[Edit: This is not a duplicate question, The so-called original question is very generic]
const double pi = 3.14;
const double *cptr = π
*cptr = 42; // 1
double dval = 3.14;
cptr = &dval; // 2