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

后端 未结 5 427
花落未央
花落未央 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:20

    This is a way to initialize an array at the same time that you create it.

    This code

    char *array[]= { "a", "b", "c" };
    

    will have the same result as this code.

    char *array[3];
    
    array[0] = "a";
    array[1] = "b";
    array[2] = "c";
    

    Here is a good source for more information.

    http://www.iu.hio.no/~mark/CTutorial/CTutorial.html#Strings

    EDIT:

    char array[3]; is an array of 3 char. char *array[3]; is an array of 3 pointers to char.

提交回复
热议问题