Home > Backend Development > C++ > body text

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

WBOY
Release: 2023-09-07 11:21:08
forward
877 people have browsed it

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
Copy after login

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;
}
Copy after login

Output

3 3 3 3 3 0 5 5 5 5
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template