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

前端 未结 13 1182
礼貌的吻别
礼貌的吻别 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条回答
  •  执笔经年
    2020-11-22 08:17

    For the case of an array of single-byte elements, you can use memset to set all elements to the same value.

    There's an example here.

提交回复
热议问题