預設為初始化純量型別
下列範例適用於 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;
}