In C, when there are many repeated values, we can use a shorthand array notation to define array. Below program demonstrates same.
// C program to demonstrate working of shorthand // array rotation. #include <stdio.h> int main() { // This line is same as // int array[10] = {1, 1, 1, 1, 0, 0, 2, 2, 2, 2}; 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.
This article is contributed by Kaushik Annangi. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- How can I return multiple values from a function?
- Return values of printf() and scanf() in C/C++
- What are the default values of static variables in C?
- std::tuple, std::pair | Returning multiple values from a function using Tuple and Pair in C++
- C function argument and return values
- Storage of integer and character values in C
- How to return multiple values from a function in C or C++?
- What’s difference between “array” and “&array” for “int array[5]” ?
- Pointer to an Array | Array Pointer
- Difference between pointer to an array and array of pointers
- Jagged Array or Array of Arrays in C with Examples
- Array of Structures vs. Array within a Structure in C/C++
- Why C treats array parameters as pointers?
- Pointer vs Array in C
- Do not use sizeof for array parameters
- What is the difference between single quoted and double quoted declaration of char array?
- Are array members deeply copied?
- How to pass a 2D array as a parameter in C?
- How to dynamically allocate a 2D array in C?
- What is Array Decay in C++? How can it be prevented?

