二维数组的存储是按行存储,先存第一行,存完后再存储第二行。二位数组仍然是连续的一片存储空间,其中数组名代表数组的开头,a[0][0]
[root@localhost CH01]# cat arr_2d.c
#include<stdio.h>
#include<stdlib.h>
#define M 2
#define N 3
int main()
{
int a[M][N];
int i,j;
for(i = 0; i < M; i++)
{
for(j = 0; j < N; j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
exit(0);
}
[root@localhost CH01]# make arr_2d
cc arr_2d.c -o arr_2d
[root@localhost CH01]# ./arr_2d //由于是auto类型,未赋值时,输出随机
419588804195536
0-169986624032764
[root@localhost CH01]# cat arr_2d.c
#include<stdio.h>
#include<stdlib.h>
#define M 2
#define N 3
int main()
{
int a[M][N];
int i,j;
for(i = 0; i < M; i++)
{
for(j