Initialization of all elements of an array to one default value in C++?

前端 未结 13 1256
礼貌的吻别
礼貌的吻别 2020-11-22 07:59

C++ Notes: Array Initialization has a nice list over initialization of arrays. I have a

int array[100] = {-1};

expecting it to be full with

13条回答
  •  猫巷女王i
    2020-11-22 08:21

    With {} you assign the elements as they are declared; the rest is initialized with 0.

    If there is no = {} to initalize, the content is undefined.

提交回复
热议问题