int x[1000] = {0, };
This is about the initialization, where a , appears without an operand on its right.
My compiler reports an error.
Thinking it might(?) differ from both C and C++, I am tagging both of them.
int x[1000] = {0, };
This is about the initialization, where a , appears without an operand on its right.
My compiler reports an error.
Thinking it might(?) differ from both C and C++, I am tagging both of them.
Since the possible duplicate question is about programming language syntax in general, here's the answer in C/C++ particularly:
C11(ISO/IEC 9899:201x) §6.7.9 Initialization
Syntax
initializer:
assignment-expression
{ initializer-list }
{ initializer-list , }
I've committed the rest, note the comma here.
In C++, it's similar, note the comma opt, which means an optional comma.
C++11(ISO/IEC 14882:2011) §8.5 Initializers [dcl.init]
A declarator can specify an initial value for the identifier being declared. The dentifier designates an object or reference being initialized. The process of initialization escribed in the remainder of 8.5 applies also to initializations specified by other syntactic contexts, such as the initialization of function parameters with argument expressions (5.2.2) or the initialization of return values (6.6.3).
initializer:
= initializer-clause
( expression-list )
initializer-clause:
assignment-expression
{ initializer-list ,opt }
{ }
initializer-list:
initializer-clause
initializer-list , initializer-clause
From ISO/IEC 9899:TC3 6.7.8 Initialization
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].
So at least for c99 it is absoloutly legal!