The Difference Between const int * And int *const

Updated:

TL;DR

const int *x; /* the value pointed to by x is constant */
int *const y; /* the address stored in y is constant */
const int *const z; /* both the address stored in z and the value pointed to by z are constants */

Read it backwards

An easy way to remember whether it is the pointed value or the address stored in the pointer variable to be constant is to read the declaration backward, following the Clockwise/Spiral Rule technique. We talk about this technique in another Dev Tip. Here we apply it to various combinations of the keyword const with a pointer, which confuses very quickly.

The trick is to read the declaration backward. So for example:

const char *cptr_x;

Here we can read: cptr_x is a pointer to a char contant. So, the value pointed to is constant, not the pointer itself. Instead if we have:

char *const cptr_y;

Now we read: cptr_y is as constant pointer to a char. So, the address stored in cptr_y is constant. Finally, if we have:

const char *const cptr_z;

This time we read: cptr_z is a constant pointer to a char constant.

Crystal clear, now!