I want to declare a large array with every value set to DEFAULT_VALUE in initialization except three values at places throughout the array.
Writing int array[2048] = { DEFAULT_VALUE };
will fill the whole array with the default, and
int array[2048] = { [4] = VALUE_1, [123] = VALUE_2, [2047] = VALUE_3 };
will set specific indexes and the rest to zero (it is in global space), but how can I initialize the array to have specific values AND my own default value? Can I write my own initialization routine?
Speed is a priority here btw.
int array[2048] = { DEFAULT_VALUE };will fill the whole array with the default" - no, it won't. It will fill in only the 1st element withDEFAULT_VALUE, the rest of the elements will be value-initialized to 0 instead.