C语言数组
数组:可以保存多个同种类型的数据
定义数组:数组类型 数组名称[ 元素个数 ];
//只有定义没有初始化的数组里放的是垃圾值(不确定的值)
#include <stdio.h>
int main()
{
int scores[6];
// 先定义数组再对数进行初始化
int scores[0] = 6;
int scores[1] =5;
int scores[3] = 7;
int scores[4] = 9;
int scores[5] = 2;
int scores[6] = 10;
// 可定义数组的同时进行初始化
// int scores[6] = {6,5,7,9,2,10};
// 指定元素个数的同时对数组进行部分显示初始化
// int scores[6] ={[1] = 5, [2] = 2};
// 注意点:使用变量定义的数组不可以定义数组的同时对数组进行初始化
// 使用变量作为元素个数:C99不支持使用变量作为元素个数,但llvm编译器,它支持
循环遍历数组
遍历:把数组中每一个元素都访问一遍
index 下标
for (int index = 0; index < 6; index++) {
printf("%d\n",scores[index]);
}
return 0;
}