Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to use designated initialize to specify which elements of an array to be initialized in C

1 Answer

0 votes
#include <stdio.h>

int main(void) 
{
    int array[] = { [3] = 89, [5] = 34, [12] = 897, [15] = 6, [17] = 1987 };
    
    for (int i = 0; i <= 17; i++)
        printf("array[%d] = %d\n", i, array[i]);
    
    return 0;
}
    
/*
run:
 
array[0] = 0
array[1] = 0
array[2] = 0
array[3] = 89
array[4] = 0
array[5] = 34
array[6] = 0
array[7] = 0
array[8] = 0
array[9] = 0
array[10] = 0
array[11] = 0
array[12] = 897
array[13] = 0
array[14] = 0
array[15] = 6
array[16] = 0
array[17] = 1987

*/

 



answered Aug 25, 2017 by avibootz

Related questions

...