How can I declare a two-dimensional array of pointers and initialize it by null pointers in c++ ?
I tried to do this
int *arr[20][30]= nullptr;
You can aggregate initialize the array with empty initializer list,
int *arr[20][30] {};
// or
int *arr[20][30] = {};
(emphasis mine)
If the number of initializer clauses is less than the number of members
and bases (since C++17)or initializer list is completely empty, the remaining membersand bases (since C++17)are initializedby their default member initializers, if provided in the class definition, and otherwise (since C++14)by empty lists, in accordance with the usual list-initialization rules (which performs value-initialization for non-class types and non-aggregate classes with default constructors, and aggregate initialization for aggregates).
Then all the elements of arr (i.e. the sub-array int* [30]) would be aggregate-initialized with empty initializer list too, then all the elements of sub-array with type int* would be value-initialized,
otherwise, the object is zero-initialized.
At last elements with type int* (which is built-in type) are all zero-initialized to null pointers.
If
Tis a scalar type, the object's initial value is the integral constant zero explicitly converted toT.