一、概念
二、代码
#include <stdio.h>
int main()
{
#pragma 1.取出数组中所有的值,称之为遍历
int scores[6] = {2,3,5,6,22,44};
/*
printf("scores[0] = %i\n",scores[0]);
printf("scores[1] = %i\n",scores[1]);
printf("scores[2] = %i\n",scores[2]);
printf("scores[3] = %i\n",scores[3]);
printf("scores[4] = %i\n",scores[4]);
printf("scores[5] = %i\n",scores[5]);
*/
// 注意 : 在遍历数组的时候, 尽量不要把遍历的次数写死
// 遍历多少次应该 由数组来决定 , 也就是说遍历多少次 应该通过数组计算得出
/*
printf("scores = %lu\n",sizeof(scores)); // 计算出数组中占用的总字节数
printf("socre[0] = %lu\n",sizeof(scores[0])); // 计算出数组中某一个元素占用的字节数
printf("一个有多少个元素 : %lu\n",sizeof(scores) / sizeof(scores[0]));
*/
// 动态计算数组的元素个数
int length = sizeof(scores) / sizeof(scores[0]);
for (int i = 0; i < length; i++) {
printf("scores[%i] = %i\n",i,scores[i]);
}
return 0;
}