Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

8,365 questions

11,625 answers

573 users

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

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial


22 views
asked Aug 25, 2017 by avibootz
edited Aug 26, 2017 by avibootz

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
...