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

Viewed 280

Here, I have initialized array like this :

#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;
}

Output :

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

Here, I have selected array index 7 as a a[7] = 4 and thereafter added some elements. Then print array elements of index 7, 8 and 9 and print correctly.

So, Is it correct output of index 8 and 9 without explicitly defined it? Why sequence does not start from index 3?

2 Answers
Related