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

后端 未结 8 1216
生来不讨喜
生来不讨喜 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:54

    In C/C++, pointers and arrays are (almost) equivalent. int *a; a[0]; will return *a, and a[1]; will return *(a + 1)

    But array can't change the pointer it points to while pointer can.

    new int[n] will allocate some spaces for the "array"

提交回复
热议问题