From the standard.
"To default-initialize an object of type T means: -- if T is a non-POD class type
[the case like vector], the default constructor for T is called."
The constructor notation T()
is used to express the default value of type T and that this is zero for built in types and the default constructor for user-defined types. The construct POD()
produces value initialisation and according to the stdandard, which results in all members and sub members being either default constructed or zero initialised.
This is why your statement is legal, but is it zero initialized as per the standard; needs some detailed lookup IMHO.
BUT, i could not find in the standard where the it defines the meaning of default construction for built in types.
EDIT:-
struct S { int x; };
void f () {
S s1; // s1.x is uninitialized here
S s2 = S(); // s2.x is zero here
}
I think we often make up our own interpretation of what default construction applied to built in types means; because the C++ standard doesn't define it (atleast i could not find it) and i remember Stroustrup or Josuttis say that it means T()
which is described as being value initialisation is "zero converted to type T" for built in types.
Since int*
is a built-in type it is initialized to zero.
But i am really not sure.