Array Initialise selected indexes

#include <stdio.h>

#define ARRAY_SIZE(n) (sizeof(n)/sizeof(n[0]))

int main()
{
	int i;
	int arr[] = {
		[3] = 3,
		[5] = 5,
	};

	for (i = 0; i < ARRAY_SIZE(arr); i++)
		printf("arr[%d] = %d\n", i, arr[i]);

	return 0;
}

Output:

arr[0] = 0
arr[1] = 0
arr[2] = 0
arr[3] = 3
arr[4] = 0
arr[5] = 5
Advertisements