Say I have an array of pointers to integers (i.e each element is a pointer to int)
int** ptrArray;
and I want to prevent changes to the integers pointed by the entries of the array
where do I need to put the const?
1. const int ** ptrArray
2. int const ** ptrArray
3. int *const* ptrArray
4. int ** const ptrArray
are there any rules for this? like "first const protects data", "second const protects the pointer" and so on?
Is there any logic behind the location of the const? any connection between where to put and what it protect?
this is very a confusing issue for me and I would really appriciate if someone can give me any guide or link to where I can read more about how and where to use the const based on what I want to protect (in case I need to use const in a 3dimensional array or so)