Array initialization at declaration

arrays, c

Solution

Yes, using designated initializers (introduced in C99), you can write code like this:

int array[10] = {[9] = 42};

which is equivalent to:

int array[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 42};

This feature is also available in some compiler as an extension, for instance, GCC.

Problem

I have a variable of type `int array[10]`. Is it possible to initialize only the last item of the array?

Original source