在指定符以严格递增的方式初始化元素后元素是否存在?

Are the elements present after a designator initializes elements in strictly increasing manner?

在这里,我已经像这样初始化了数组:

#include <stdio.h>

int main() 
{
    int a[10] = {1, 2, 3, [7] = 4, 8, 9};

    printf("a[7] = %d\na[8] = %d\na[9] = %d\n", a[7], a[8], a[9]);

    return 0;
}

输出:

a[7] = 4
a[8] = 8
a[9] = 9

在这里,我选择了数组索引 7 作为 a[7] = 4,然后添加了一些元素。然后打印索引789的数组元素并正确打印。

那么,索引 89 没有明确定义的输出是否正确? 为什么序列不从索引 3?

开始

Why sequence does not start from index 3?

因为,事情不是这样的!!

引用 C11,第 6.7.9 章 指定初始化器强调我的

Each brace-enclosed initializer list has an associated current object. When no designations are present, subobjects of the current object are initialized in order according to the type of the current object: array elements in increasing subscript order, structure members in declaration order, and the first named member of a union.148) . In contrast, a designation causes the following initializer to begin initialization of the subobject described by the designator. Initialization then continues forward in order, beginning with the next subobject after that described by the designator.149)

因此,在您的情况下,在指示符 [7] 之后,大括号括起来的列表中剩余的两个元素将用于初始化下一个子对象,索引 8 中的数组元素和9.

只是为了添加更多相关信息,

If a designator has the form

[ constant-expression ]

then the current object (defined below) shall have array type and the expression shall be an integer constant expression. [...]

Is it correct output of index 8 and 9 without explicitly defined it?

是的,这是正确的。编译器将在索引 7.
之后初始化数组元素 初始化程序将前三个元素初始化为 123。索引 7 处的元素将具有值 4。索引 7 之后的两个元素将分别具有值 89

Why sequence does not start from index 3?

指定初始化器[7]告诉编译器在索引7之后继续初始化数组元素。