Synex
Synex

Reputation: 213

New Operator with and without Parentheses

What is the main difference between using the new operator to create an array with trailing parentheses and without? That is, the difference between the following declarations

void* ptr = new int[5]();

and

void* ptr = new int[5];

Upvotes: -2

Views: 104

Answers (1)

463035818_is_not_an_ai
463035818_is_not_an_ai

Reputation: 123114

Details of the new expression are explained here. In your example there is

new type new-initializer

The type is an array of 5 integers in both cases. The () is the new-initializer. Details of initialization are explained in this section. For integers default initialization (no ()) means the elements are not initialized and value initialization means the elements are initialized with a 0 value.

Upvotes: 2

Related Questions