NOTE: this is just copy-pasting from stackoverflow and some textbooks, see references below.
const: meaning roughly “I promise not to change this value.” This is used primarily to specify interfaces so that data can be passed to functions using pointers and references without fear of it being modified. The compiler enforces the promise made by
const. The value of a
constcan be calculated at runtime.
constexpr: meaning roughly “to be evaluated at compile time.” This is used primarily to specify constants, to allow placement of data in read-only memory (where it is unlikely to be corrupted), and for performance. The value of a
constexprmust be calculated by the compiler.
You should read from right to left. This is refered to as clockwise/spiral rule
int *pointer to int
int const *==
const int *pointer to const int
int * constconst pointer to int
int const * const==
const * constconst pointer to const int
int **pointer to pointer to int
int ** constconst pointer to pointer to int
int * const *pointer to const pointer to int
int const **pointer to pointer to const int
int * const * constconst pointer to const pointer to int.