使用`int a [3] = {0,};`格式在c中初始化数组. [英] Initialize array in c in the format `int a[3]={0,};`

查看:92
本文介绍了使用`int a [3] = {0,};`格式在c中初始化数组.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到一个源,其中数组在 int arr [3] = {0,}; 中进行初始化?我通常使用这种格式 int arr [3] = {0}; 我可以知道有什么区别

I had seen a source where array initialize in int arr[3] ={0,}; What does it mean ? I normally use this format int arr[3]={0}; can i know what is the difference

推荐答案

这可能是 dup ,但是我不管怎样,我都会开枪.

This is probably a dup, but I'll take a shot anyhow.

int arr [3] = {0,}; int arr [3] = {0}; 之间没有区别.

参考:C11 6.7.9:

Ref: C11 6.7.9:

    initializer:
         assignment-expression
         { initializer-list }
         { initializer-list , }

两种形式的初始值设定项列表均被视为初始值设定项.在结尾处带有逗号的形式是许多人所首选的形式,因为它使在代码维护过程中更容易重新排列元素或将元素添加到列表中.

Both forms of initializer lists are considered initializers. The form with the comma at the end is preferred by many because it makes it easier to rearrange or add elements to the list during code maintenance.

 int arr[3] ={0,}; 

声明一个包含三个元素的数组,并将第一个元素初始化为0.进行部分初始化时,该数组的其余部分将自动用零初始化.

declares an array of three elements and initializes the first element to 0. When you do a partial initialization, the rest of the array is automatically initialized with zeros.

参考C11 6.7.9:

Ref. C11 6.7.9:

如果用大括号括起来的列表中的初始化程序少于那里的初始化程序是集合中的元素或成员,或者用于初始化大小已知的数组的字符串文字是数组中的元素,则聚合的其余部分应为隐式初始化为与具有静态存储的对象相同持续时间.

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.

这篇关于使用`int a [3] = {0,};`格式在c中初始化数组.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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