char *array and char array[]

前端 未结 4 800
心在旅途
心在旅途 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:13

    It's very similar to

    char array[] = {'O', 'n', 'e', ' ', /*etc*/ ' ', 'm', 'u', 's', 'i', 'c', '\0'};
    

    but gives you read-only memory.

    For a discussion of the difference between a char[] and a char *, see comp.lang.c FAQ 1.32.

提交回复
热议问题