Is "new int[8]()" equivalent to "new int[8]{}" in C++11?

673 views Asked by At

Is new int[8]() equivalent to new int[8]{} in C++11?

In other words:

Does the C++11 standard guarantee each of new int[8]() and new int[8]{} returns a zero-initialized array?

1

There are 1 answers

0
Nicol Bolas On BEST ANSWER

new int[8]() will, by [dcl.init]/17.4, be value-initialized. Since it is an array, [dcl.init]/8.3 tells us that value initializing an array means to value-initialize each element.

new int[8]{} will, by [dcl.init.list]/3.2, invoke aggregate initialization on the array. Since there are no elements in the braced-init-list, each of the remaining elements in the array (ie: all 8) will be initialized "from an empty initializer list" ([dcl.init.aggr]/8). Which, after dancing through [dcl.init.list] again, leads you to 3.4, which tells you that "from an empty initializer list" for non-aggregate types means value-initializiation.

So yes, they both evaluate to the same thing.