How could I simple initialize a multidimensional C-array with 0 elements like this:
int a[2][2] = { { 0, 0 }, {0, 0} }
How could I simple initialize a multidimensional C-array with 0 elements like this:
int a[2][2] = { { 0, 0 }, {0, 0} }
Use memset:
memset(a,0,sizeof a);
This should work:
int a[2][2] = {0};
EDIT This trick may work for silencing the warning:
int a[2][2] = {{0}};
Either use memset()
, or make it static and just "lazy-initialize" to zero:
static int a[2][2];
Variables with static storage class are always initialized as if all all their fields were set to 0.
Use bzero to nullify it (faster than memset):
bzero(a, sizeof(a));
Simple: add a semicolon at the end:
int a[2][2] = { { 0, 0 }, {0, 0} };
And, if all the initializers really are zero and the array isn't local, you can omit the initializer altogether because 0 is the default:
int a[2][2];
People are suggesting calling memset or bzero, but those aren't relevant to the question as given.