Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
GreenGeeks Web Hosting - Faster, Scalable & Eco-Friendly

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


Distribute your Resume to 500+ Job Boards & Recruiters


7,788 questions

10,874 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


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