Simple sharing of two-dimensional arrays in C language!

Two-dimensional arrays in C language
Last time we briefly talked about one-dimensional arrays, and after a few days, let's talk about two-dimensional arrays! This time the definition of the array is not explained. Directly talk about the use of two-dimensional arrays!
Define a two-dimensional array:
int arr[3][3]
Here, similarly, int is the type of the two-dimensional array; arr is the name of the array; the first [3] means that the two-dimensional array has 3 rows , The subscripts of these 3 rows are 0 1 2 respectively, and the second [3] indicates that this two-dimensional array has 3 columns, and the subscripts of these three columns are 0 1 2 respectively. The purpose of saying this is to explain [array subscripts start from 0]
Assignment of two-dimensional array: The
first assignment method:
int arr[3][3]={1,2,3,4,5,6 , 7,8,9}, this assignment is the total number of assignments in the array, the array of 3 rows 3 after the assignment as:
0 1 2 3 line
line 1456
, line 2789
of
Assignment method in column 0, column 1, column 2, column 2 :
int arr[3][3]={ {1,2,3},{4,5,6},{7,8,9}}
a large There are also 3 curly brackets in the brackets. The three curly brackets denote line 0, line 1, and line 2 from left to right. The three numbers in the first brace represent column 0, column 1, and column 2 from left to right.
The 3 rows and 3 columns of the assigned array are:
row 0 1 2 3 row 1
4 5 6
row 2 7 8 9
column 0 column 1 column 2
third assignment method:
int arr[3] [3]={1,2,3}
The number in braces is less than the number in the array, and the assignment principle will be respected. The default value of the system without assignment is 0.
The 3 rows and 3 columns of this array after assignment are :
row 0, 1 2 3
, 1 Row 0 0 0
Row 2 0 0 0
Column 0 Column 1 Column 2
There is also the following situation:
int arr[3][3]={ {1},{2},{3}}
After assignment The 3 rows and 3 columns of this array are:
Row 0 1 0 0 Row 1
2 0 0 Row 2
3 0 0
Column 0 Column 1 Column 2
Note: If the number of braces in the assignment exceeds the number If the number specified in the array is set, the system will report an error! ! ! ! !
If you don't see any changes after reading this, you can combine these types of assignments and read them several times to realize the assignment method!
There are also calls to two-dimensional arrays, let's talk about it next time! good night! ! !

Guess you like

Origin blog.csdn.net/qq_46216951/article/details/108904337