What\'s the difference between:
char * const
and
const char *
const
always modifies the thing that comes before it (to the left of it), EXCEPT when it's the first thing in a type declaration, where it modifies the thing that comes after it (to the right of it).
So these two are the same:
int const *i1;
const int *i2;
they define pointers to a const int
. You can change where i1
and i2
points, but you can't change the value they point at.
This:
int *const i3 = (int*) 0x12345678;
defines a const
pointer to an integer and initializes it to point at memory location 12345678. You can change the int
value at address 12345678, but you can't change the address that i3
points to.