数组的三种使用方法
#include<iostream>
using namespace std;
int main(){
cout << " ————————————————————数组的三种使用方法————————————————————" << endl;
cout << "" << endl;
cout << "第一种: 数据类型 数组名 [数据个数]" << endl;
int arr[5];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
arr[3] = 40;
arr[4] = 50;
for(int i = 0; i < 5; i++){
cout << arr[i] << endl;
}
cout << "第二种: 数据类型 数组名 [数组个数] = {数值1,数值2,.....}" << endl;
int arr2[5] = {10,20,30,40,50};
for(int m = 0; m < 5; m++){
cout << arr[m] << endl;
}
cout << "第三种: 数据类型 数组名 [] = {数值1,数值2,.....}" << endl;
int array[] = {60,70,80,10,60};
for(int j = 0; j < 5; j++){
cout << array[j] << endl;
}
return 0;
}