You can either have typed pointers or a void pointer here.
So the typed pointers will access the memory as if it specified type uh, to use if you cast a pointer
to a different type and the reference it, the memory will be treated as containing the cast type.
It really makes sense to do this, but the void pointer cannot bear the reference, so you can never
access data through the void pointer.
So to access the data you have to cast the pointer here.
The full reason for this void pointer type is that it can point to anything.
In general, void pointer should only be used when the type does not matter to that function.
So for example, the C malloc function returns the void pointer because the function merely allocates
memory.
It does not care what the memory will be used for.
So here pointers also can declared as const here so which depending on where you apply it means that
the memory of the pointer points to is read only through the pointer or the value of the pointer is
read only.
So now I want to create some character const this.
We're going to make a character PTC const here.
So hello.
And then pointer.
See here h here and const.
Character PTC here.
See, I'm going to comment it out.
All of this.
So for more understanding here and make it look nice and PTC.
We hear.
And.
Character.
Const.
Keep.
I would make it.
See?
And CP equals here on the underscore E here and C plus plus or C plus plus actually because we're going
to use this C plus plus.
So now, um, the C can be used as a pointer.
See can be used as a pointer.
And here it's okay to write like that.
Okay, but can we write?
Right through the pointer.
Here and here.
As you can see, we declared and we're going to convert the pointer pointer pointer to constant.
And here.
It's okay to and it can read the memory memory pointed to here.
But here, as you can see here, the ID road as an error because we cannot write to the memory.
And here we go.
It's okay because it's constant pointer.
We're going to be creating a new constant pointer here.
Constant pointer.
And here we are.
We can write.
We can write through the pointer and we cannot point it here.
This cplusplus we cannot point to anything else.
Anything else?
So here the C is a pointer to a constant character that is the output.
You can change the points to and you can read what it points to, but you cannot use it to change the
memory here.
So on the other hand, the CP here.
C p here.
The CP is a constant pointer, so which means you can both read and write the memory which the pointer
points to, but you cannot change the way it points to.
So it is typical to pass the constant character pointers to functions because the functions do not know
where the string has been allocated or the size of the buffer here.
So the caller may pass a literal which cannot be changed.
But not that there is a not no const operator.
So character const is treated as const character and a pointer to a constant buffer here.
So you can make pointer constant, uh, change it or remove it using cast.
And now we're going to create another code here.
Here.
We're going to let's make let's comment this out and make new here.
So here, character C and hello.
And here character pointer constant CP one C here and we're going to add comments after we completed
our code here.
Here.
And cost character PTC.
And Constcast.
We're going to use Constcast here.
Constcast.
Const character.
And cp1.
And here, PTC Plus.
Plus.
And after that character comes to const char const.
Cast and character.
Const here and p, t, c and lastly here CP to.
A.
Here.
So.
You can make a point at constant change it or remove it by using the casts here.
And this code here does some fairly pointless changing around the const keyword to prove the point.
So the pointers cp1 here.
Cp1 and CP2.
Can be used to change the memory they point to, but once assigned, neither can point to other memory
here.
So the first const cast here, as you can see, const cast here casts away the const ness to a pointer
that can be changed to point to other memory here, but cannot be used to alter that memory.
So memory in this case, it's a PTC here.
So the second const cast casts away the constants of PTC here so that the memory can be changed through
the pointer CP to.