A shorthand array notation in C for repeated values
In C, when there are many repeated values, we can use a shorthand array notation to define array. Below program demonstrates same.
#include <stdio.h>
int main()
{
int array[10] = {[0 ... 3]1, [6 ... 9]2};
for ( int i = 0; i < 10; i++)
printf ( "%d " , array[i]);
return 0;
}
|
Output:
1 1 1 1 0 0 2 2 2 2
Note that middle gap of 2 is automatically filled with 0.
Last Updated :
18 Sep, 2017
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...