Viliami Viliami - 4 months ago 38
C++ Question

Difference between int * array[60] and int * array = new int(60);

int * array[60]; //creates an array of 60 pointers to an int
int * array = new int(60); //same thing?

Do these both result in the same type of array? e.g an array of pointers to integers

I know that the first one uninitialized, and the second one is initialized, but I am unsure of what exactly the second one creates.

int * array = new int(60); //same thing?

No, they're not the same thing. array is just a pointer here, and then point to an int with initialized value 60.

If you meant int * array = new int[60];, array will point to an array of 60 ints, they're still not the same thing.

Note that just as the declaration, int* array means it is a pointer, while int* array[60] means it is an array (of 60 pointers). (Array might decay to pointer, i.e. int** for int* array[60], it's not same as int*.)