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

后端 未结 23 1902
清歌不尽
清歌不尽 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:17

    For delayed initialization (i.e. class member constructor initialization) consider:

    int a[4];
    
    unsigned int size = sizeof(a) / sizeof(a[0]);
    for (unsigned int i = 0; i < size; i++)
      a[i] = 0;
    

提交回复
热议问题