Simpler way to set multiple array slots to one value

前端 未结 10 2221
我寻月下人不归
我寻月下人不归 2021-02-18 16:31

I\'m coding in C++, and I have the following code:

int array[30];
array[9] = 1;
array[5] = 1;
array[14] = 1;

array[8] = 2;
array[15] = 2;
array[23] = 2;
array[1         


        
10条回答
  •  长情又很酷
    2021-02-18 17:07

    I remember, for static initialization exist syntax like:

    int array[30] = {
      [9] = 1, [8] = 2
    }
    

    And so on. This works in gcc, about another compilers - I do not know.

提交回复
热议问题