24 lines
458 B
C++
24 lines
458 B
C++
// 扩展 new 和 delete
|
|
// 数组的 new 和 delete
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
int main()
|
|
{
|
|
// 使用拓展的 new 创建类对象数组
|
|
int *p = new int[6]{1, 2, 3, 4, 5, 6};
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
cout << *(p + i) << endl;
|
|
}
|
|
delete[] p; // 释放数组空间
|
|
|
|
cout << "--------------------" << endl;
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
cout << *(p + i) << endl;
|
|
}
|
|
return 0;
|
|
}
|