https://en.cppreference.com/w/cpp/language/zero_initialization shows that zero-initialization happens in the following scenario:
int array[32] = {};
; but never says anything about this:
int array[32] = { 0 };
Does the latter also zero-initialize the whole array in c++, or only the first element? If so, is it also true for structs?
int array[4] = { 1 };would produce{1, 0, 0, 0}so don't think the latter syntax initializes the whole array with that value.int array[32] = {};results in the compiler outputting the following: "untitled2.c:1:17: warning: ISO C forbids empty initializer braces [-Wpedantic]" suggest:int array[32] = {0};Notice the initializer inside the braces. However, if you want to use a value other than 0, suggest:for( size_t i = 0; i< 32; i++ ) { array[i] = 1; }