Zero an array in C code
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicates:
How to initialize an array to something in C without a loop?
How to initialize an array in C
号
如何在不使用for或任何其他循环的情况下将已知数组大小归零?
例如:
1 | arr[20] = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0; |
这是很长的路…我需要它的捷径。
1 | int arr[20] = {0}; |
C99
If there are fewer initializers in a brace-enclosed list than there are elements or members
of an aggregate, or fewer characters in a string literal used to initialize an array of known
size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.
1 2 |
MemSet查看参考
注意:你可以用MemSet与任何字符。
例子:
1 2 |
也可能是预充
1 2 |
但在carefull。它不是一个有限大小的数组,你可以很容易地造成严重的伤害到你的程序做一些像这样:
1 2 |
它是去工作(在Windows)和零后的存储器阵列。它可能会伤害到其他变量的值。
人bzero
1 2 3 4 5 6 7 8 9 10 11 | NAME bzero - write zero-valued bytes SYNOPSIS #include <strings.h> void bzero(void *s, size_t n); DESCRIPTION The bzero() function sets the first n bytes of the byte area starting at s to zero (bytes containing '\0'). |
如果它只会
利用
1 2 |