We have the following statement from Stephen Prath's book - C ++ Programming Language (6th edition). Page 330:
You can assign the address of both constant and non-constant data to a pointer to a constant, assuming that the data itself is not a pointer, but you can assign the address of non-constant data only to a non-constant pointer.
In my understanding, the following things are available, which coincides with the first part of the author's opinion:
const int a = 5; int b = 6; const int * ptr = &a; //Допустимая операция, невозможно изменить значение a через указатель и переменную a. const int * ptr2 = &b; //Допустимая операция, невозможно изменить значение b через указатель, но возможно через переменную b. However, part of the statement about “but assigning the address of non-constant data is allowed only to a non-constant pointer” causes a misunderstanding, according to the author’s logic the following action is unacceptable:
int a = 5; int * const ptr = &a; //Недопустимо, так как указатель константный, указывает на не константный тип. However, this code is successfully compiled, which seems to me quite logical, because as a result we get a pointer without the possibility of changing the address, but nothing prevents to change the value of the variable through the pointer (* ptr).
Actually the question is what the author is trying to convey and what I misunderstood from his statement?