Actually int const *constant_ptr;
is the same as const int *ptr_to_constant;
. The const
keyword affects the element at left, if there's not, it will affect the element at right.
int const *constant_ptr;
, here the element at the left of const
is int
.
const int *ptr_to_constant;
, here const
doesn't have an element at left, so it applies to te right one, which is int
.
const int *ptr_to_constant;
Here, only the value pointed by the pointer is constant.
int *const constant_ptr;
Here, the pointer is constant.
int const *constant_ptr;
Here, only the value pointed by the pointer is constant.
int const * const constant_ptr_to_constant;
Here, the pointer and the value pointed by it are constants.
EDIT:
int const *constant_ptr;
, you call the pointer constant_ptr
, but if I keep your name scheme, it should be called ptr_to_constant
.