Share via


Default Initialization of Scalar Types

The following sample works in Visual C++ .NET 2003 as specified in the standard:

Example

// 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;
}

These variables should both be zero: 0 and 0

See Also

Other Resources

Visual C++ .NET 2003 Enhanced Compiler Conformance