Dynamic arrays initialization

Pick and discuss which is the sanest method.

1
2
3
4
5
6
7
int *i1 = new int[20];
int *i2(new int[20]);
int *i3{new int[20]};

int *i4 = new int[20]();
int *i5(new int[20]());
int *i6{new int[20]()};

I would write
std::unique_ptr<int[]> i1(new int[20]); and
std::unique_ptr<int[]> i2(new int[20]());respectively (they do different things you know), since I'm not yet used to curlies everywhere.
they do different things you know

The first group behaves like malloc(), and the second like calloc(), filling the allocated memory with zeros, from what I remember. Correct?
Yes, that's about right
Topic archived. No new replies allowed.