What does that mean in c? char *array[]= { “**”, “**”, “**” };

后端 未结 5 479
花落未央
花落未央 2021-01-13 10:45

In some code that I read, there was an initializing statement like this

char *array[]= { \"something1\", \"something2\", \"something3\" };

5条回答
  •  天命终不由人
    2021-01-13 11:35

    It declares array as an array of 3 pointers to char, with its 3 elements initialized to pointers to the respective strings. The memory is allocated for the array itself (3 pointers) and for the strings. The strings memory is allocated statically. The array's memory is allocated either statically (if the declaration is outside of all functions) or dynamically (typically, on the execution stack of the CPU) if the declaration is inside a function.

提交回复
热议问题