How do I create an array in C++ which is on the heap instead of the stack?

后端 未结 7 1991
小蘑菇
小蘑菇 2021-02-07 05:55

I have a very large array which must be 262144 elements in length (and potentially much larger in future). I have tried allocating the array on the stack like so:



        
7条回答
  •  春和景丽
    2021-02-07 06:04

    As the number is not necessarily known at compile time, the type is a pointer:

    int *myArray = new int[262144];
    

提交回复
热议问题