简体   繁体   中英

c++ iteration exception over int array

why does the code cause exception ?

exception: Access violation writing location 0x000001A88BF5D000.

int* ints = new int(1000000);
for (int i = 0; i < 1000000; i++)
{
    ints[i] = 1;
}

You're allocating a single integer. If you want to allocate an integer array, you should use square brackets.

int* ints = new int[1000000]();

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