Home  >  Article  >  Backend Development  >  Is there a shorthand array notation for repeated values ​​in C?

Is there a shorthand array notation for repeated values ​​in C?

WBOY
WBOYforward
2023-09-07 11:21:08836browse

Is there a shorthand array notation for repeated values ​​in C?

An array stores multiple values ​​of the same data type. For an array, there may be situations where the same 2-3 values ​​need to be stored, that is, 3,3,3,3 need to be stored.

For this situation, the programming language C provides a simple way to create an array containing such repeated values ​​to reduce the programmer's workload.

Syntax

[startofRepeatingSeq … EndofRepeatingSeq]number
Example : For 3 repeated 5 times ;
[0 … 4]3

Example

#include <stdio.h>
int main() {
   int array[10] = {[0 ... 4]3, [6 ... 9]5};
   for (int i = 0; i < 10; i++)
      printf("%d ", array[i]);
   return 0;
}

Output

3 3 3 3 3 0 5 5 5 5

The above is the detailed content of Is there a shorthand array notation for repeated values ​​in C?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete