C/C++ 中的简短数组表示法
如果 C 中存在重复值,我们使用简短数组表示法来定义该数组。
请看下面的示例
示例代码
#include <stdio.h>
int main() {
int array[10] = {[0 ... 3]7, [4 ... 5]6,[6 ... 9]2};
for (int i = 0; i < 10; i++)
printf("%d ", array[i]);
return 0;
}输出
7 7 7 7 6 6 2 2 2 2
此程序中,
int array[10] = {[0 ... 3]7, [4 ... 5]6,[6 ... 9]2}与以下内容类似,
int array[10] = {7, 7, 7, 7, 6, 6, 2, 2, 2, 2}.如果数组中间有任何间隙,将会由 0 填充。
在 C++ 中,上述程序会给出相同输出,但将在输出处显示警告。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP