1

I want to know the difference between

int *pia=new int[10];

and

int *pis=new int[10]();

In other words, I want to know what is in the pia when it is not initialized but has been allocated memory space.

1 Answer 1

3

The first specifies default initialisation; for simple types like int, this means there is no initialisation and they have unspecified values.

The second specifies value initialisation; for simple types like int, this means they are initialised with a value of zero.

Sign up to request clarification or add additional context in comments.

2 Comments

Does the newer uniform initialisation syntax int *pis=new int[10]{}; also work in this case?
@Niall: Yes, that also gives value initialisation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.