Objective C const NSString * vs NSString * const

后端 未结 2 1635
温柔的废话
温柔的废话 2020-12-22 19:18

I\'m trying to a NSString constant in my .h file to be defined in my .m. I understand that
extern NSString * const variableName; in the .h and
<

2条回答
  •  攒了一身酷
    2020-12-22 19:33

    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.

提交回复
热议问题