int *array = new int[n]; what is this function actually doing?

后端 未结 8 1185
生来不讨喜
生来不讨喜 2020-12-03 05:00

I am confused about how to create a dynamic defined array:

 int *array = new int[n];

I have no idea what this is doing. I can tell it\'s c

8条回答
  •  Happy的楠姐
    2020-12-03 05:38

    The new operator is allocating space for a block of n integers and assigning the memory address of that block to the int* variable array.

    The general form of new as it applies to one-dimensional arrays appears as follows:

    array_var = new Type[desired_size];
    

提交回复
热议问题