c++ initial value of dynamic array

后端 未结 6 718
清酒与你
清酒与你 2020-12-15 17:12

I need to dynamically create an array of integer. I\'ve found that when using a static array the syntax

int a [5]={0};

initializes correctl

6条回答
  •  猫巷女王i
    2020-12-15 17:51

    Value initialize the elements with ()

    Example:

    int *p = new int[10];       // block of ten uninitialized ints
    int *p2 = new int[10]();    // block of ten ints value initialized to 0
    

提交回复
热议问题