I want to initialize all elements of the array to zero or nullptr
struct Window{ int a;};
int main()
{
Window* list[4] = { 0, 0, 0, 0 };
Window* list2[4] = {0};
Window* list3[4] = {};
Window* list4[4]{ 0, 0, 0, 0 };
Window* list5[4]{0};
Window* list6[4]{};
}
I understand that when initializing at least one member for any value, all the others are initialized to zero, so if I do this:
int list[4] = { 6 };
The first member becomes 6, and all the rest are initialized to zero. I am confused, however, with:
int list[4]{0};
and
int list[4]{};
I assume that the empty square brackets immediately after the declaration without an equal sign is what is called initialization of zero, in contrast to the initialization by default, but there is one too int list[4]{0}, right? Is it connected std::initializer_listbehind the scenes or not? I thought they were used only for non-POD types, so why std::initializer_listnot here?