#include <stdio.h> int main() { int i; //遍历输出分别值 int a[]={1,2,3,4,5}; for(i=0;i<5;i++){ printf("%d\t",a[i]); //1 2 3 4 5 }; printf("\n"); //若给的值不够就用0补齐 int b[10]={1,2}; for(i=0;i<10;i++){ printf("%d\t",b[i]); //1 2 0 0 0 0 0 0 0 0 } printf("\n"); //不给值则默认为0,初始化也可以用这种方式 int c[10]={}; for(i=0;i<10;i++){ printf("%d\t",c[i]); //0 0 0 0 0 0 0 0 0 0 } printf("\n"); //这种写法是C99独有,可以挑选任意位更改值 int d[5]={ [0]=2,[2]=2,3, }; for(i=0;i<5;i++){ printf("%d\t",d[i]); //2 0 2 3 0 } printf("\n"); //下面是如何确定数组长度 printf("%d\t",sizeof(a)); //20 printf("%d",sizeof(a[0])); //4 所以可以得出20/4=5 printf("\n"); //公式就是sizeof(a)/sizeof(a[0]) printf("%d",sizeof(a)/sizeof(a[0])); //5 }
标签:C语言,int,基础知识,索引,数组,main From: https://www.cnblogs.com/vv-77/p/17309846.html