#include <iostream>
using namespace std;
int main()
{
int *p = new int(5);
int *q = new int[5]{1,2,3,4,5};
int a[5]={ 1,2,3 };
p[1] = 2;
q[5] = 6;
a[5] = 6;
for (int i = 0;i <= 5;i++)
{
cout << p[i] << endl;
}
for (int i = 0;i <= 5;i++)
{
cout << q[i] << endl;
}
for (int i = 0;i <= 5;i++)
{
cout << a[i] << endl;
}
system("pause");
delete p; //Heap corruption detected
delete[] q; /*Heap corruption detected与p情况一样,使用的数组长度超过申请的数组长度并不会报错,并且可以正常使用,但是在销毁时,只销毁了申请的数组内存,超出的内存未删除,且没有指针指向这块内存,便会报错*/
return 0;
}
Heap corruption detected与p情况一样,使用的数组长度超过申请的数组长度并不会报错,并且可以正常使用,但是在销毁时,只销毁了申请的数组内存,超出的内存未删除,且没有指针指向这块内存,便会报错;