How to initialize only specific elements of an array in C

1 Answer

0 votes
#include <stdio.h>

#define SIZE 16

int main(void) {
    int arr[SIZE] = { [0] = 41, [5] = 67, [3] = 99, [10] = 68, [13] = 96, [11] = 51};

    for (int i = 0; i < SIZE; i++) {
        printf("%d ", arr[i]);
    }

    return 0;
}




/*
run:

41 0 0 99 0 67 0 0 0 0 68 51 0 96 0 0

*/

 



answered May 19, 2022 by avibootz
...