我想知道在堆中创建的对象中的内置类型是否会初始化为零?它是由标准强制还是编译器特定?C++堆对象的初始化
考虑下面的代码:
#include <iostream>
using namespace std;
struct test
{
int _tab[1024];
};
int main()
{
test *p(new test);
for (int i = 0; i < 1024; i++)
{
cout << p->_tab[i] << endl;
}
delete p;
return 0;
}
运行时,它打印全部为零。
请参阅Johannes答案http://stackoverflow.com/questions/808464/c-new-call-that-behaves-like-calloc – 2012-02-04 15:37:51