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

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

    If your compiler is GCC you can use following syntax:

    int array[1024] = {[0 ... 1023] = 5};
    

    Check out detailed description: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Designated-Inits.html

提交回复
热议问题