C++ float array initialization [duplicate] C++ float array initialization [duplicate] arrays arrays

C++ float array initialization [duplicate]


You only initialize the first N positions to the values in braces and all others are initialized to 0. In this case, N is the number of arguments you passed to the initialization list, i.e.,

float arr1[10] = { };       // all elements are 0float arr2[10] = { 0 };     // all elements are 0float arr3[10] = { 1 };     // first element is 1, all others are 0float arr4[10] = { 1, 2 };  // first element is 1, second is 2, all others are 0


No, it sets all members/elements that haven't been explicitly set to their default-initialisation value, which is zero for numeric types.