A quote from Ben Clemens ’s book , Language C in the 21st Century (Chapter 8, Keyword const):
Ads should be read right to left. In this way:
int const
- constant integer;int const *
- (non-constant) pointer to a constant integer;int * const
is a constant pointer to a (non-constant) integer;int * const *
is a pointer to a constant pointer to integer;int const * *
- pointer to a pointer to a constant integer;int const * const *
is a pointer to a constant pointer to a constant integer.
As you can see, the const
qualifier always refers to what is to its left — just like *
.
You can rearrange the type name and const
, that is, int const
and const int
are the same (although this trick with const
and *
will not succeed). I prefer the int const
form because it is consistent with more complex constructs and the right-to-left reading rule. But the const int
form is more common, perhaps because it is easier to pronounce in ordinary language (a constant integer) or because it has always been done this way. One way or another, both options are suitable.
In article on Habré So you think you know Const? go a step further and add a third const
qualifier:
int const * const * const
is a constant pointer to a constant pointer to a constant integer.
char* const*
without const would bechar**
i. This is an array of constant strings. - nick_n_a