char *array and char array[]

前端 未结 4 818
心在旅途
心在旅途 2020-12-07 13:25

if I write this

 char *array = \"One good thing about music\";

I actually create an array? I mean it\'s the same like this?



        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 14:16

    No. Actually it's the "same" as

    char array[] = {'O', 'n', 'e', ..... 'i','c','\0');
    

    Every character is a separate element, with an additional \0 character as a string terminator.

    I quoted "same", because there are some differences between char * array and char array[]. If you want to read more, take a look at C: differences between char pointer and array

提交回复
热议问题