简体   繁体   中英

Allocating space for an array

I have a C++ program that dynamically allocates an array of integers. In the final function below I can't figure out how to allocate space for the array, new int[*arrPtr]; is what I had in mind after reading the chapter on pointers, and it compiles properly, but the program crashes. Could anyone take a look at my code and point me in the right direction?

I greatly appreciate any assistance on this matter, thank you very much for your time.

It's not

new int[*arrPtr]

It's

arrPtr = new int[num]; //num is the size of the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM