C语言基础 -28 数组_ 二维数组之深入理解

对于二维数组,a[0]代表第一行,a[1]代表第2行; 每一行又包括n列元素

book@100ask:~/C_coding/CH01$ cat 2d_array.c
#include<stdio.h>
#include<stdlib.h>
#define M 2
#define N 3

int main()
{
int i,j;
int a[M][N] = {1,2,3,4,5};
printf("a = %p\n",a);
printf("a+1 = %p\n",a+1);

for(i = 0; i < M; i++)
{
	for(j = 0; j < N; j++)
	{
	printf("%p --> %d\n",&a[i][j],a[i][j]);
	}
	printf("\n");
}

}


book@100ask:~/C_coding/CH01$ make 2d_array
cc     2d_array.c   -o 2d_array
book@100ask:~/C_coding/CH01$ ./2d_array 
a = 0x7ffc49725b30
a+1 = 0x7ffc49725b3c
0x7ffc49725b30 --> 1
0x7ffc49725b34 --> 2
0x7ffc49725b38 --> 3

0x7ffc49725b3c --> 4
0x7ffc49725b40 --> 5
0x7ffc49725b44 --> 0

由上,二位数组首地址即数组的默认地址。

a+1的地址,为数组的第2行的首地址

猜你喜欢

转载自blog.csdn.net/f2157120/article/details/106760223
今日推荐