How to initialize only few elements of an array with some values?

后端 未结 4 721
梦如初夏
梦如初夏 2020-12-04 23:31

This might be a stupid question, but is it possible to assign some values to an array instead of all? To clarify what I want:

If I need an array lik

4条回答
  •  孤街浪徒
    2020-12-05 00:32

    Here is my trivial approach:

    int array[12] = {0};
    array[0] = 1; array[4] = 2; array[8] = 3;
    

    However, technically speaking, this is not "initializing" the array :)

提交回复
热议问题