That code is equivalent to:
const int nNums= 4;
int* nums[nNums] = {0, 0, 0};
int d[nNums];
So, nums
is an array of int*
s of length 4, with all four elements initialized to null; d
is an array of int
s of length 4, with all four elements uninitialized (to reemphasize, d
does not get initialized in any way).
The syntax = {0, 0, 0}
in this context is known as "aggregate initialization", and is described in §8.5.1 of the C++03 standard; the relevant portion for this code (§8.5.1/2) states:
When an aggregate is initialized the initializer can contain an initializer-clause consisting of a brace-enclosed, comma-separated list of initializer-clauses for the members of the aggregate, written in increasing subscript or member order. If the aggregate contains subaggregates, this rule applies recursively to the members of the subaggregate.
So, the first three elements of nums
are explicitly initialized to 0
, and the fourth element is implicitly "value-initialized", as stated in §8.5.1/7:
If there are fewer initializers in the list than there are members in the aggregate, then each member not explicitly initialized shall be value-initialized.
Value-initialization is described in §8.5/5:
To value-initialize an object of type T
means:
- if
T
is a class type with a user-declared constructor, then the default constructor for T
is called (and the initialization is ill-formed if T
has 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 T
is value-initialized;
- if
T
is an array type, then each element is value-initialized;
- otherwise, the object is zero-initialized
To zero-initialize an object of type T
means:
- if
T
is a scalar type, the object is set to the value of 0
(zero) converted to T
;
- if
T
is a non-union class type, each nonstatic data member and each base-class subobject is zero-initialized;
- if
T
is a union type, the object’s first named data member) is zero-initialized;
- if
T
is an array type, each element is zero-initialized;
- if
T
is a reference type, no initialization is performed.
This results in the fourth element of nums
also being initialized to null.