零用C code数组 [英] Zero an array in C code

查看:117
本文介绍了零用C code数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能显示的文件:结果
  <一href=\"http://stackoverflow.com/questions/2891191/how-to-initialize-an-array-to-something-in-c-without-a-loop\">How初始化数组在C的东西没有一个循环?结果
  如何初始化用C 数组


我怎么可以零数组的大小已知不使用的或任何其他循环?

例如:

 改编[20] = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0;

这是很长的路要走......我需要它的简便方法。


解决方案

  INT改编[20] = {0};

C99 [$ 6.7.8 / 21]


  

如果有一个大括号括起来的列表更少的初始化值多于元件或部件
  聚合,或在一个字符串更少的字符的字面用于初始化的已知阵列
  尺寸比有数组中的元素,的总的剩余部分应为具有静态存储持续时间对象初始化隐含相同



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

How can I zero a known size of an array without using a for or any other loop ?

For example:

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

This is the long way... I need it the short way.

解决方案

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 code数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆