The Standard says (8.5/5
)
To default-initialize an object of type T means:
— if T is a non-POD class type (clause 9), the default constructor for T is called (and the initialization is ill-formed if Thas no accessible default constructor);
— if Tis an array type, each element is default-initialized;
— otherwise, the object is zero-initialized.
.
To value-initialize an object of type T means:
— if Tis a class type (clause 9) with a user-declared constructor (12.1), then the default constructor for T is called (and the initialization is ill-formed if Thas no accessible default constructor);
— if T is a non-union class type without a user-declared constructor, then every non-static data member and base-class component of Tis value-initialized;
— if Tis an array type, then each element is value-initialized;
— otherwise, the object is zero-initialized
.
Is the value it gets implementation defined or is it the same for all implementations?
So the value would be same for all implementations.
Struct
is non-POD type so
Struct *a =new Struct; // default initialization
//memberVariable will be initialized to 0 because if T is a non-POD class type
//the default constructor for T is called
Struct *b = new Struct(); //value initializes Struct, which calls the default ctor.
//memberVariable will be initialized to 0 in this case also.
EDIT :
As @Johannes noticed the primitive type (int, bool, float, enum, pointer) member variable is value-initialized
not default initialized
.