The C++ const word define a real, constant (unlike C #define which is just a text macro).
const int number=123;
Will create a constant (non changeable) integer. However, pointers get confuse from time to time, so here are some pointers (ha ha…) on how to remember them:
const int * myPtr;
Is a pointer to a constant. later on, the pointer itself can point to something else.
int const * myPtr;
Is actually means the same thing. However
int * const myPtr;
means that the pointer is constant (can’t point to anything else) but the line
will work just fine.
And of course, the combination of the two will create an unchangeable pointer to an unchangeable object:
const int * const myPtr;
This last usage is not very common.
How to remember
Generally? const qualifies the left “thing” it has. If there is nothing on the left, it will qualify the first from the right. * on the left means pointer, while object type means the object itself.