Static array vs. dynamic array in C++

后端 未结 11 1639
遥遥无期
遥遥无期 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:22

    Yes right the static array is created at the compile time where as the dynamic array is created on the run time. Where as the difference as far is concerned with their memory locations the static are located on the stack and the dynamic are created on the heap. Everything which gets located on heap needs the memory management until and unless garbage collector as in the case of .net framework is present otherwise there is a risk of memory leak.

提交回复
热议问题