直接上结果
#include <iostream>
using namespace std;
int main() {
int* A = new int[10];
int* B = new int[10]();
for(int i = 0; i < 10; ++i) {
cout << A[i] << " ";
}
cout << endl;
for(int i = 0; i < 10; ++i) {
cout << B[i] << " ";
}
cout << endl;
return 0;
}
0 536870912 0 536870912 -957349872 32767 -1114432673 32767 -957337400 32767
0 0 0 0 0 0 0 0 0 0
由结果可知new int[10] 只初始化第一个数为0, new int[10] ()将分配的内存全部初始化为 0