Static array vs. dynamic array in C++

后端 未结 11 1547
遥遥无期
遥遥无期 2020-11-22 10:43

What is the difference between a static array and a dynamic array in C++?

I have to do an assignment for my class and it says not to use static arrays, only dynamic

11条回答
  •  长情又很酷
    2020-11-22 11:05

    Static Array :

    1. Static arrays are allocated memory at compile time.
    2. Size is fixed.
    3. Located in stack memory space.
    4. Eg. : int array[10]; //array of size 10

    Dynamic Array :

    1. Memory is allocated at run time.
    2. Size is not fixed.
    3. Located in Heap memory space.
    4. Eg. : int* array = new int[10];

提交回复
热议问题