Determining the Length of a String Literal

后端 未结 7 1714
栀梦
栀梦 2020-12-16 12:45

Given an array of pointers to string literals:

char *textMessages[] = {
    \"Small text message\",
    \"Slightly larger text message\",
    \"A really larg         


        
7条回答
  •  感动是毒
    2020-12-16 13:45

    I'll tell you something, as per my Knowledge arrays an pointers are the same thing except when you use sizeof.

    When you use sizeof on a pointer it will return always 4 BYTE regardless the thing that pointer points to, but if it used on array it will return How long the array is big in bytes?.

    In you example here *textMessage[] is array of pointer so when you use sizeof(textMessage[2]) it will return 4 BYTE because textMessage[2] is a pointer.

    I hope it'll be useful for you.

提交回复
热议问题