Fastest way to zero out a 2d array in C?
- by Eddy
I want to repeatedly zero a large 2d array in C. This is what I do at the moment:
for(j = 0; j < n; j++)
{
for(i = 0; i < n; i++)
{
array[i][j] = 0;
}
}
I've tried using memset:
memset(array, 0, sizeof(array))
But this only works for 1D arrays. When I printf the contents of the 2D array, the first row is zeroes,…