How to initialize all members of an array to the same value?

后端 未结 23 1823
清歌不尽
清歌不尽 2020-11-21 04:34

I have a large array in C (not C++ if that makes a difference). I want to initialize all members of the same value.

I could swear I

23条回答
  •  天涯浪人
    2020-11-21 05:05

    For initializing 'normal' data types (like int arrays), you can use the bracket notation, but it will zero the values after the last if there is still space in the array:

    // put values 1-8, then two zeroes
    int list[10] = {1,2,3,4,5,6,7,8};
    

提交回复
热议问题