You could use cdecl to understand what a C declaration means.
const int **foo;
declare foo as pointer to pointer to const int
thus you can change pointers, but not the value they're pointing to.
int * const * const foo;
declare foo as const pointer to const pointer to int
this, instead, is a cosnt pointer, pointing to a const pointer, to a non-const int: you cannot change pointed value, but it can be changed.
C uses the Clockwise/Spiral Rule, in a case where you have only modifiers at the left side of the variable (of foo) you read stuff going from right to left:
int(5) *(4) const(3) *(2) const(1) foo;
foo
is a constant(1) pointer(2) to constant(3) pointer(4) to an integer(5).
int(6) const(5) *(4) const(3) *(2) const(1) foo;
const(6) int(5) *(4) const(3) *(2) const(1) foo; // [same as above]
In this case foo
is a constant(1) pointer(2) to constant(3) pointer(4) to a constant(5) integer(6) [or to an integer(5) which is constant(6)].
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…