-
Notifications
You must be signed in to change notification settings - Fork 1
/
41二维数组.c
51 lines (36 loc) · 974 Bytes
/
41二维数组.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*二维数组*/
#include <stdio.h>
int main(){
/*
定义: 类型 数组名[数组的数量][子数组的长度] ;
*/
//第一种方式:
int arr[3][4]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
//第二种方式:
int arr1[3][4];
arr1[0][0]=1;
arr1[0][1]=2;
arr1[0][2]=3;
arr1[0][3]=4;
arr1[1][0]=1;
arr1[1][1]=2;
arr1[1][2]=3;
arr1[1][3]=4;
arr1[2][0]=1;
arr1[2][1]=2;
arr1[2][2]=3;
arr1[2][3]=4;
//使用: 数组名[数组角标][子数组中数据角标];
printf("%d\n",arr1[2][2]);
//传递子数组时传递的是地址
printf("%p\n",arr1[2]);
//子数组数量控制行数,单个子数组长度控制列数.
//打印一个二维数组
for (int i=0; i<3; i++) {
for (int j=0; j<4; j++) {
printf("%d\t",arr1[i][j]);
}
printf("\n");
}
return 0;
}