标量类型的默认值初始化
下面的示例在 Visual C++ .NET 2003 中工作在该标准上指定:
示例
// default_initialization_of_scalar_types.cpp
struct S
{
int i0;
int i1;
S() : i1() // i1 default initialized to 0, i0 value indeterminate
{
}
};
extern "C" int printf_s(const char*, ...);
int main()
{
// points to unitialized int (value at *pi0 is indeterminate)
int *pi0 = new int;
// pointer to a default initialized int (*pi1 == 0)
int *pi1 = new int();
S s;
printf_s("These variables should both be zero: %d and %d\n",
*pi1, s.i1);
delete pi0;
delete pi1;
}