initialize a multidimensional C array of variable size to zero

后端 未结 5 2001
小蘑菇
小蘑菇 2021-02-08 07:03

I want to initialize a two-dimensional array of variable size to zero. I know it can be done for a fixed-sized array:

int myarray[10][10] = {0};
<
5条回答
  •  太阳男子
    2021-02-08 07:32

    Online C99 Standard (n1256 draft), Section 6.7.8, para 3:

    The type of the entity to be initialized shall be an array of unknown size or an object type that is not a variable length array type.

    Emphasis mine.

    As everyone else has said, your best bet is to use memset().

提交回复
热议问题