The difference between int* p=new int[N] and int* p=new int(N)

int *p = new int(N);

This statement allocates a section of memory, initializes an object of type int by value, and returns its pointer to the defined p. The initial value of int pointed to by p is 0.

 int *p = new int[N];

The meaning of this statement is: allocate a piece of memory and store N int objects continuously like an array, these ints are initialized by default. For the int type, its initial value is uncertain. Return the pointer of the first int to p.

Guess you like

Origin blog.csdn.net/qq_44165430/article/details/105255082