一、一维数组和二维数组比较
二、二维数组
#include <stdio.h>
void Show(int (*arr)[4] , int row ,int col)
{
for (int i = 0 ; i<row ; i++)//遍历行
{
for (int j = 0 ; j<col ; j++)//遍历列
{
printf ("%-3d ",arr[i][j]);
}
printf ("\n");//每一行就回车
}
}
int main()
{
//二维数组:** 行优先 **
//二维数组的初始化:
int arr[3][4];
int brr[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};
int crr[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12};
printf ("%d %d\n\n",&crr[0][4],&crr[1][0]);//这里说明二维数组的存放方式是(如图一)
int drr[3][4] = {1,2,3,4,5,6};
drr[2][1] = 1;//修改其中的一项的值
int err[3][4] = {0,0,0,0,0,0,0,0,0,1};//只初始化其中一项的值
int frr[][4] = {1,2,3,4,5,6,7,8,9,10};//凸显二维数组的 “行优先”
//int frr[3][] = {1,2,3,4,5,6,7,8,9,10};//error
Show(crr,3,4);
return 0;
}