C_learn/2_lesson/02_array_init/main.c

25 lines
612 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
int main(int argc, char *argv[])
{
// 一维数组的初始化
// 如果不初始化,直接使用会是随机值
// int a[4];
// 初始化方式1全部初始化
// int a[4] = {123, 78, 666, 476};
// 如果是全部初始化,可以不指定数组元素的个数,系统会自动分配
// int a[] = {10, 20, 30, 40};
// 初始化方式2局部初始化
// 未初始化的位置的元素自动赋值为0
int a[4] = {10, 20};
printf("%d\n",a[0]);
printf("%d\n",a[1]);
printf("%d\n",a[2]);
printf("%d\n",a[3]);
return 0;
}