Fastest way to zero out a 2d array in C?

前端 未结 12 1288
后悔当初
后悔当初 2021-01-29 18:58

I want to repeatedly zero a large 2d array in C. This is what I do at the moment:

// Array of size n * m, where n may not equal m
for(j = 0; j < n; j++)
{
            


        
12条回答
  •  无人共我
    2021-01-29 18:59

    memset(array, 0, sizeof(array[0][0]) * m * n);
    

    Where m and n are the width and height of the two-dimensional array (in your example, you have a square two-dimensional array, so m == n).

提交回复
热议问题