c++ - 以下类型的声明是否完全有效?

标签 c++ c arrays

<分区>

int x[1000] = {0, }; 

这是关于初始化的,, 右边没有操作数。

我的编译器报告了一个错误

考虑到它可能(?)不同于 CC++,我标记了它们。

最佳答案

来自 ISO/IEC 9899:TC3 6.7.8 初始化

26 EXAMPLE 3

The declaration

int y[4][3] = {
{ 1, 3, 5 },
{ 2, 4, 6 },
{ 3, 5, 7 },
};

is a definition with a fully bracketed initialization: 1, 3, and 5 initialize the first row of y (the array object y[0]), namely y[0][0], y[0][1], and y[0][2]. Likewise the next two lines initialize y[1] and y[2]. The initializer ends early, so y[3] is initialized with zeros. Precisely the same effect could have been achieved by

int y[4][3] = {
1, 3, 5, 2, 4, 6, 3, 5, 7
};

The initializer for y[0] does not begin with a left brace, so three items from the list are used. Likewise the next three are taken successively for y[1] and y[2].

所以至少对于 c99 来说它是绝对合法的!

关于c++ - 以下类型的声明是否完全有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19092035/

相关文章:

c++ - ZZ坐标不匹配

c++ - 从 C++(或 C)回调调用 python 方法

c++ - 无法从类方法访问类变量

c - 关于C中数组的各种问题

c - 无法通过 C 中的串行/COM 端口发送 MIDI 数据

javascript - 将 base64 字符串转换为 ArrayBuffer

c++ - g++ 相对路径

c - 什么是覆盖数据?

php - 如何使用 SMARTY 创建带有多维数组的 HTML 表格?

c# - C# 中的二维数组以及如何返回数组