<分区>
int x[1000] = {0, };
这是关于初始化的,, 右边没有操作数。
我的编译器报告了一个错误。
考虑到它可能(?)不同于 C 和 C++,我标记了它们。
<分区>
int x[1000] = {0, };
这是关于初始化的,, 右边没有操作数。
我的编译器报告了一个错误。
考虑到它可能(?)不同于 C 和 C++,我标记了它们。
最佳答案
来自 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/