Difference between const void * a and void * const a, and constvoid
Const void *
This defines a pointer a. a can point to any type of value, but it must point to a constant.
In this case, we cannot modify the object to which the pointer is directed, but we can point the pointer to another object.
For example:
Const void * a; * a = 0x123; // It cannot be compiled because * a contains a const value. The const value cannot be changed.
Const int m = 1; const int n = 2;
A = & m; a = & n; // compilation is successful.
Void * const
This defines a const pointer a. a can point to any type of value, but a is a constant pointer to an object.
We cannot modify the address stored in the pointer, but we can modify the object pointed to by the pointer.
For example:
Void * const a; this definition: * a = 0x123; no problem,
However, a = (void *) & B; is not acceptable because a is a const variable.
For example:
Int m = 1; nt n = 2;
A = & m; a = & n; // compilation fails.
In this case, const modifies * a in const void *. In void * const a, const modifies.