This is very basic, so my suggestion is to read a basic C++ book.
Despite of that I'll provide the answer.
int p = 10;
It is a statement which declares and defines a variable named p
of type int
.
The content of this variable can be modified. That's because the variable p
is not const.
Obviously the later statement p = 13;
is still valid and it assigns a new value to that variable.
Now you have this:
const int* ptr = &p;
You're defining a pointer, named ptr
which points to that variable.
Adding the qualifier const
to the pointer it simply means that you cannot modify the content of the variable by means of the access of the pointer itself.
In other words, the pointer can be only used (for example) for reading the value of p
.
On the other hand:
int* pr = &p;
defines a pointer which is not more const
qualified.
Indeed, you can access and modify the content of the variable p
by means of the usage of that pointer itself. (*pr = 19;
is a valid statement).
A little bit far...
This is the general idea behind behind a "more complex world".
The statement:
const int* ptr = &p;
it's possible because the a variable can be implicitly converted in its const
version.