Converting array of pointers to double pointer

后端 未结 3 1497
别跟我提以往
别跟我提以往 2021-01-27 09:51

I am able to do this:

char * months[] = {\"empty\",\"jan\",\"feb\",\"mar\",\"apr\",\"may\",\"jun\",\"jul\",\"aug\",\"sep\",\"oct\",\"nov\",\"dec\"};

unsigned sh         


        
3条回答
  •  囚心锁ツ
    2021-01-27 10:39

    I’m afraid what you wish to do is not possible. This is not how C works, char ** and char * [n] are two different things when it comes to types, so you won’t be able to initialize a char ** with an entity of type char * [n].

    The equivalent for your char** case would be:

    char **x = (char *[]){"hello", "world"};
    

    If you need this only for the initialization then keep it as it is using char * [n], it’s the right way to declare it.

    You can always refer it as char ** anyway.

提交回复
热议问题