Objective C const NSString * vs NSString * const

Solution 1:

It's not the same. The const modifier can be applied to the value, or the pointer to the value.


int * const

A constant pointer (not modifiable) to an integer (its value can be modified)


const int *

A modifiable pointer to a constant integer (its value can't be modified)


So you can imagine:

const int * const;

Solution 2:

Constant pointer is NOT a pointer to constant. Constant pointer means the pointer is constant. E.g. constant pointer int * const ptr2; indicates that ptr2 is a pointer which is constant. This means that ptr2 cannot be made to point to another integer. However, the integer pointed by ptr2 can be changed.

Whereas a pointer to constant const int * ptr1; indicates that ptr1 is a pointer that points to a constant integer. The integer is constant and cannot be changed. However, the pointer ptr1 can be made to point to some other integer.