Search code examples
carraysinitialization

Initialize mulitdimensional C-array with 0 elements


How could I simple initialize a multidimensional C-array with 0 elements like this:

int a[2][2] = { { 0, 0 }, {0, 0} }

Solution

  • This should work:

    int a[2][2] = {0};
    

    EDIT This trick may work for silencing the warning:

    int a[2][2] = {{0}};