C strings confusion

前端 未结 7 2158
深忆病人
深忆病人 2020-11-27 14:30

I\'m learning C right now and got a bit confused with character arrays - strings.

char name[15]=\"Fortran\";

No problem with this - its an

7条回答
  •  一向
    一向 (楼主)
    2020-11-27 14:46

    char* name is just a pointer. Somewhere along the line memory has to be allocated and the address of that memory stored in name.

    • It could point to a single byte of memory and be a "true" pointer to a single char.
    • It could point to a contiguous area of memory which holds a number of characters.
    • If those characters happen to end with a null terminator, low and behold you have a pointer to a string.

提交回复
热议问题