#include <iostream>
using namespace std;
int main()
{
struct str
{
int a[10000];
};
str* temp;
int count = 0;
cout << "sizeof(str) = " << sizeof(str) << endl;
for(int i = 0;i < 10;i++)
{
count++;
temp = new str[100];
cout << "count = " << count << "temp = " << temp << endl;
cout << "*temp = " << (temp->a[i]) << endl;
if(temp == NULL)
break;
delete temp;
}
return 0;
}
如果将delete temp去掉,10次循环的输出结果不同,主要是因为空间没有释放,如果
把for循环变成无限循环,则依旧会停止,主要是再没有空间可分配的时候,会break。