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

后端 未结 8 1187
生来不讨喜
生来不讨喜 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条回答
  •  暖寄归人
    2020-12-03 05:35

    new allocates an amount of memory needed to store the object/array that you request. In this case n numbers of int.

    The pointer will then store the address to this block of memory.

    But be careful, this allocated block of memory will not be freed until you tell it so by writing

    delete [] array;
    

提交回复
热议问题