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