数组:
数组是一种数据的格式,能够储存多个同类型得到值
数组的创建需要指定:
1.储存在每个元素中值的类型
2.数组的名称
3.数组中的元素
1.创建一个数组
short months[12];
2.为数组中的元素赋值
#include<math.h>
#include <iostream>
using namespace std;
void Example_A(){
short months[12];//定义一个数组
months [0]=1;//为第一个值赋值
months [1]=2;//为第二个值赋值
int alist[3]={3,4,5} ;//批量赋值
}
int main(){
int x;
Example_A();
return 0;
}
3.使用数组里的元素
#include<math.h>
#include <iostream>
using namespace std;
void Example_A(){
int alist[3]={3,4,5} ;//批量赋值
cout<<alist[0];
}
int main(){
int x;
Example_A();
return 0;
}
总结:
数组的定义需要加上类型,
数组的赋值和使用需要角标
角标是从0开始的。