------<a href= "http://www.itheima.com" target= "blank" >java training, Android training, iOS training,. NET training </a>, look forward to communicating with you! -------
Two-dimensional arrays:
Can be seen as a special one-dimensional array, and each element of this one-dimensional array is a one-dimensional array
Definition of a two-dimensional array
Data type array name [length of first dimension (row)] [Length of second Dimension (column)];
int a[2][3];
Understanding Method:
1) This is a special one-dimensional array, one-dimensional array has two elements a[0] a[1]
A[0] It also stores a one-dimensional array with an array length of 3
2) defines a matrix of 2 rows and 3 columns
Initialization of two-dimensional arrays
1) Simultaneous initialization of the definition
(1) Full initialization
int a1[2]={1,2};
1, a special one-dimensional array, the first dimension has 2 elements
int a[2][3]={{12,23,45},{1,2,3}}; Segmentation
12 23 45
1 2 3
2. Continuous Assignment
int a[2][3]={1,2,3,4,5,6};
3, can omit the first dimension
int a[][3]={{1,2,3},{3,4,5},{3,4,5}}; int a[3][3]
int a[][2]={1,2,3,4,5,6,7,8}; int a[4][2]
(2) Partial initialization
In general, we used to initialize the array to 0.
int a[3][4]={1};
1 0 0 0
0 0 0 0
0 0 0 0
int a[3][4]={{1},{2},{3}};
1 0 0 0
2 0 0 0
3 0 0 0
Note: The first-dimensional length of this notation can be omitted
int a[3][4]={1,2,3,4,5};
1 2 3 4
5 0 0 0
0 0 0 0
Omit the first dimension
2) Define first, then initialize
int a[3][4];
First-Dimension subscript: 0 1 2
Second-dimension subscript: 0 1 2 3
A[0][0] = 1;
Traversal of two-dimensional arrays:
Accesses each element of a two-dimensional array
How do I access it?
Access by subscript
int a[3][4];
| 0 1 2 3
--------------------------------
0 | 00 01 02 03
1 | 10 11 12 13
2 | 20 21 22 23
Dark Horse programmer--c Language Foundation---Two-dimensional array