Important concepts of one-dimensional arrays:
Discussion of the array a[10].
1. a represents the array name, which is the address of the first element, i.e., the address of the element a[10].
2. a is an address constant, so any occurrence of a++, or a=a+2 assignments are errors.
3. a is a one-dimensional array name, so it is a column pointer; that is, a+1 jumps one column.
Discussion of the array a[3][3].
1. a represents the array name, which is the address of the first element, i.e., the address of the element a[10].
2. a is an address constant, so any occurrence of a++, or a=a+2 assignments are errors.
3. a is a two-dimensional array name, so it is a row pointer; that is, a+1 jumps one row.
4. a[0], a[1], a[2] are also address constants; they cannot be assigned values, and they are all column pointers; a[0]+1, a[1]+1, a[2]+1 all jump one column.
5. Note that a and a[0], a[1], a[2] are different; their base types are different. The former is a row of elements, while the latter are columns of elements.
Techniques for solving problems with two-dimensional arrays:
If there is a[3][3]={1,2,3,4,5,6,7,8,9} type of question.
Step one: Write them as: First column Second column Third column
a[0]→ 1 2 3 → First row
a[1]→ 4 5 6 → Second row
a[2]→ 7 8 9 → Third row
Step two: This way of solving problems is very simple:
*(a[0]+1) we know is the first row’s first element moving one column forward, so here it is the a[0][1] element, which is 1.
*(a[1]+2) we know is the second row’s first element moving two columns forward, so here it is the a[1][2] element, which is 6.
Be sure to remember: whenever dealing with two-dimensional array problems, write them in the above format before solving; this will make it easier.
Array initialization, both one-dimensional and two-dimensional, one-dimensional can be omitted, but the second dimension of two-dimensional must be written
int a[]={1,2} is valid. int a[][4]={2,3,4} is valid. But int a[4][]={2,3,4} is invalid.
Row pointers in two-dimensional arrays:
int a[1][2];
Here a is now a row pointer, a+1 jumps one row of array elements. Combined with (*p[2]) pointer
a[0], a[1] are now column pointers. a[0]+1 jumps one array element. Combined with *p[2] pointer array usage
Also remember the “strip method”:
a[2] becomes *(a+2), a[2][3] becomes *(a+2)[3], and can then be transformed into *(*(a+2)+3)
This concept is very important!
</x)&&(x<10) indicates greater than 0 and less than 10. <></x<10 is not permissible (be sure to remember).