这两个memset有什么区别?

What's the difference between these two memset?

int color[1001][1001];
int m,n;
m=10;
n=10;
memset(color,0,sizeof(color));
memset(color,0,sizeof(color[0][0])*m*n );

这两个 memset 语句有什么区别?

任何答案将不胜感激。提前致谢。

What's the difference between these two memset statements?

memset 函数采用目的地、值和计数。计数是 sizeof(color),第一次调用是 sizeof(int) * 1001 * 1001

第二次它将是 sizeof(int) * 10 * 10

前者将整个数组清零,而后者仅部分清零,从color[0][0]color[0][99],这依赖于数组是排成一行的——主要时尚。 C11 标准(草案 n1570)的相关摘录,§6.5.2.1 数组下标:

[…] It follows from this that arrays are stored in row-major order (last subscript varies fastest).

或者,如果 m = n = 1001mn 实际上表示数组的维度,那么这两个调用是相同的,just two different ways of writing it.