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

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

    If the array happens to be int or anything with the size of int or your mem-pattern's size fits exact times into an int (i.e. all zeroes or 0xA5A5A5A5), the best way is to use memset().

    Otherwise call memcpy() in a loop moving the index.

提交回复
热议问题