I believe it's a simple question: Is there a way to initialize an array with values that are nonzero without using loops?
One way I know is to use Range Initialization to initialize the array with the values I want. For example:
int main()
{
/* Using Designated Range Initialization*/
int my_array[10] = {[0 ... 3] = 5, [4 ... 7] = 15, [8 ... 9] = 30};
/* Using Explicit initialization for each element */
int other_array[10] = {5, 5, 5, 5, 15, 15, 15, 15, 30, 30};
return 0;
}
However, this method is just an extension of the GCC compiler, and not part of ISO C. So given this possible non-portability between systems, is there a way to do an array initialization in a similar way? Of course, without using loops.
Also, the method I'm looking for is just beyond the explicit initialization of each element of the array.