数组在上一节中提到过,那什么是遍历呢?
百度百科给出了这样的答案。
我所理解的遍历:按照程序员的需求从“盒子”里拿东西。
数组的遍历毫无疑问就是从数组中拿东西。
活学活用:将0-9之间的数字存放在数组中,用遍历的方式打印输出出来。
#include <stdio.h>
int main()
{
int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};//数组的初始化
int i;
for(i=0;i<=9;i++){
printf("\t%d\n",arr[i]);}
return 0;
}
注意事项:
- 数组的下标不要越界。
eg.
- c语言的数组长度经过定义以后,不能再次被改变。
eg.禁止动态数据类型
int n;
int a[n];
scanf("%d",&n);