How to just use "new" for a pointer of which type is int[3]?

Viewed 91

I know that we can use "new" to allocate one object or allocate an array. So how do I just new one object for an int array like below shows ? I can't think out of such way like new an int number for an array.

enter image description here

Maybe int (*p)[3] = new int[1][3]; also have same result as just allocate an array. But I want to know whether there is another way.

1 Answers

I didn't quite get what you wanna asked, but in the cppreference, there is

The new-expression returns a prvalue pointer to the constructed object or, if an array of objects was constructed, "a pointer to the initial element of the array".

Thus, new int[1][3] return a pointer point to the initial element of the array, which means the type is int[3]. So you can use it to initialize the pointer int(*p)[3], which type is int(*)[3]

I think it may help you.

Related