In the braces of the list initialization in this declaration
int a[2][2]={(1,2),(3,4)};
there are present two expressions ( 1, 2 )
and ( 3, 4 )
. They are primary expressions with the comma operator.
According to the C Standard (6.5.17 Comma operator)
2 The left operand of a comma operator is evaluated as a void
expression; there is a sequence point between its evaluation and that
of the right operand. Then the right operand is evaluated; the result
has its type and value
So the values of the expressions are 2
and 4
.
Thus in fact you have
int a[2][2]={ 2, 4 };
As a result the first sub-array of the array that is the array a[0] is initialized with these values. Elements of the second sub array a[1] are zero initialized.
If for example you would write
int a[2][2]={(1,2,3,4)};
then this declaration is equivalent to
int a[2][2]={ 4 };
and only the element a[0][0]
will be explicitly initialized by the value 4
,
Another example of using an expression with the comma operator as an initializer.
int i = 0;
int j = ( i++, i++, i++ );
As a result i
will be equal to 3
and j
to 2
.