C++ array initialization

前端 未结 4 1930
Happy的楠姐
Happy的楠姐 2020-12-02 06:26

is this form of intializing an array to all 0s

char myarray[ARRAY_SIZE] = {0} supported by all compilers? ,

if so, is there similar syntax

4条回答
  •  独厮守ぢ
    2020-12-02 06:55

    Yes, I believe it should work and it can also be applied to other data types.

    For class arrays though, if there are fewer items in the initializer list than elements in the array, the default constructor is used for the remaining elements. If no default constructor is defined for the class, the initializer list must be complete — that is, there must be one initializer for each element in the array.

提交回复
热议问题