Created
September 20, 2013 06:29
-
-
Save hazirguo/6634009 to your computer and use it in GitHub Desktop.
A very intresting method of array initliazation that I have never used before!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int array[10] = { | |
[0 ... 9] = -1, | |
[8] = 0, | |
[0] = 45, | |
[1] = 34, | |
[5] = 12, | |
}; | |
int i; | |
for (i=0; i<10; i++) | |
{ | |
printf("array[%d]=%d\n", i, array[i]); | |
} | |
return 0; | |
} | |
//Compile this program with gcc, run it, and get the result below: | |
array[0]=45 | |
array[1]=34 | |
array[2]=-1 | |
array[3]=-1 | |
array[4]=-1 | |
array[5]=12 | |
array[6]=-1 | |
array[7]=-1 | |
array[8]=0 | |
array[9]=-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment