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

后端 未结 8 1215
生来不讨喜
生来不讨喜 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 05:31

    The statement basically does the following:

    1. Creates a integer array of 'n' elements
    2. Allocates the memory in HEAP memory of the process as you are using new operator to create the pointer
    3. Returns a valid address (if the memory allocation for the required size if available at the point of execution of this statement)

提交回复
热议问题