I’m curious if these are zero initialized and all my pointers are 0 when I declare a fixed size array. I can say foo* arr[1000][1000] and I see that all the entries are 0..but I am not sure if this is something I can rely on or not. I could say foo* arr[1000][1000] = {} but this double array is a member variable in a class and I wouldn’t want to have a double for loop in the constructor if it’s not necessary…
I’m curious if these are zero initialized and all my pointers are 0 when
Share
Depends on how you allocate the array.
If it’s
staticor global, then the contents will all be initialised to 0. If it’s a local variable, then the contents won’t be initialised to anything.So since your array is a member variable, it won’t be initialised to 0 automatically. However, you can initialise all the variables to zero by using the initialisation list in the constructor thusly: