-5

How to initialize all members of an array to the same value?

Recently I read this article, it says "int arr[10] = {0};" doesn't work.
So I thought any arrays of all types of variables can't be filled without using STL. But it seeems that "int*arr[10] = {NULL}" works. I mean all the spaces are filled with NULL value. Why does this happen??

enter image description here

while using debugger

uma
  • 31
  • 1
  • The C++ specification says that an array who is only partially initialized will have the remaining elements "zero" initialized. – Some programmer dude Oct 12 '19 at 08:08
  • 1
    Where does it say `int arr[10] = {0};` won't work? That's valid and will zero initialize the array in both c and c++. – George Oct 12 '19 at 08:36

1 Answers1

1

int arr[10] = {0}

initializes the array as {0 0 0 0 0 0 0 0 0 0}

the same to the pointer array.

the unspecified values are set default to zero.

You are initializing that pointer array to ten zeros (you specified the first value to NULL but NULL is zero in c++), that is, ten nullptr.