6

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

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.