Static array vs. dynamic array in C++

后端 未结 11 1647
遥遥无期
遥遥无期 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条回答
  •  Happy的楠姐
    2020-11-22 11:01

    Static arrays are allocated memory at compile time and the memory is allocated on the stack. Whereas, the dynamic arrays are allocated memory at the runtime and the memory is allocated from heap.

    int arr[] = { 1, 3, 4 }; // static integer array.   
    int* arr = new int[3]; // dynamic integer array.
    

提交回复
热议问题