加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 值初始化聚合

发布时间:2020-12-16 09:35:34 所属栏目:百科 来源:网络整理
导读:试过C标准,但无法弄清楚.这些是等价的吗? double x[2] = {0.0,0.0}; 和 double x[2] = {}; 这些怎么样? struct A { double x[2];};A a = {0.0,0.0}; 和 A a = {}; 谢谢! 解决方法 C标准说(8.5.1): If there are fewer initializers in the list than the
试过C标准,但无法弄清楚.这些是等价的吗?

double x[2] = {0.0,0.0};

double x[2] = {};

这些怎么样?

struct A {
    double x[2];
};

A a = {0.0,0.0};

A a = {};

谢谢!

解决方法

C标准说(8.5.1):

If there are fewer initializers in the
list than there are members in the
aggregate,then each member not
explicitly initialized shall be
value-initialized

和double的值初始化是将其设置为0.0.

所以是的!在C中它们是等价的.

[我没有时间检查C99标准.]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读