1.大小确定的数组
1)用常量保存数组大小
2)声明数组
3)数组赋值
<i>用花括号列举法赋值
int list[5] = { 1,2,3,4,5 }; for (int i = 0; i < 5; i++) cout << list[i] << " "; system("pause"); return 0;
<ii>用for循环赋值
#include "stdafx.h" #include<iostream> using namespace std; int main() { const int size = 5; int list[size]; for (int i = 0; i < size; i++) list[i] = i + 100; for (int j = 0; j < size; j++) cout << "No." << j << " " << list[j] << endl; system("pause"); return 0; }
2.动态数组
3.二维数组