Consider the following code:
#include <iostream>
using namespace std;
int main(){
int* p = new int[2];
for (int i = 0; i < 2; i++)
cout << p[i] << endl;
return 0;
}
I run it several times. It always produces the following output:
0
0
Can I assume that C++ default-initialization set array elements to its default value? In this case, can I assume that p's element values are always set to 0?
I have read the following related questions. But they does not specifically address my case: