c - C代码中的数组归零

标签 c arrays

<分区>

Possible Duplicates:
How to initialize an array to something in C without a loop?
How to initialize an array in C

如何在不使用 for 或任何其他循环的情况下将已知大小的数组归零?

例如:

arr[20] = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;

这是很长的路...我需要它的捷径。

最佳答案

int arr[20] = {0};

C99 [$6.7.8/21]

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.


关于c - C代码中的数组归零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5636070/

相关文章:

javascript - 使用 Javascript 的递归方法

c - putc和putchar的性能?

Lauterbach 调试器无法在特定函数中设置断点

c++ - 在 X 个字符后限制 libcurl 返回

javascript - 数组到对象单行

c - 打印二维数组 `*((*arr+(i*3))+j)` 时 `arr` 如何工作?

javascript - 具体使用 "[]"作为参数如何工作?

c - 初始化二维宽字符数组时出错?

c - 这个脚本哪里有错误?

arrays - bash 脚本,在目录中创建所有文件的数组