C Static Array Initialization - how verbose do I need to be?

arrays, c, c++

Solution

int foo[10] = {0};

This is very fine :)

Note that if you do the following:

int foo[10] = {1};

Only the first element of the array will be initialized with the non-zero number whereas the rest will be initialized with zeros.

Problem

To initialize an int array with all zeros, do I need to use: ``` int foo[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; ``` Or, will this work: ``` int foo[10] = {0}; ```

Original source

Related problems