Knowledge Points:
Definition and reference of two-dimensional arrays: 1, two-dimensional array definition:
The definition of a two-dimensional array: Type an array group name "row Length" "Column Length";
For example:
int a "3" "2";
Defines a two-dimensional array a,3 rows 2 columns, 6 elements;
int B "5" "10";
Defines a two-dimensional array a,5 rows 10 columns, 50 elements;
Reference to a two-dimensional array: Row subscript range: 0~ line length-1;
Column The following table range: 0~ column length-1;
The storage and operation of strings can be realized by one-dimensional character array;
The definition, reference, and initialization of one-dimensional character array is the same as other types of one-dimensional arrays;
An array of 3 rows and 4 columns is defined, with a total of 3x4=12 elements and an array named A, which is:
A[0][0], a[0][1], a[0][2], a[0][3]
A[1][0], a[1][1], a[1][2], a[1][3]
A[2][0], a[2][1], a[2][2], a[2][3]
In a two-dimensional array, to locate an element, one-dimensional subscript and two-dimensional subscript must be given, as in a plane to determine a point, to know the x-coordinate and the y-coordinate. For example, A[3][4] represents the element in the 3rd row and 4th column of the A array.
Two-dimensional arrays are conceptually two-dimensional, but in-memory addresses are contiguous, meaning that each element is next to each other. So how do you store a two-dimensional array in linear memory? There are two ways to do this: one is in rows, that is, after a row is placed and then placed in the second row. The other is arranged in columns, that is, after a column is placed and then placed in the second column.
In the C language, two-dimensional arrays are arranged in rows. That is, first store a[0] rows, and then store a[1] rows, and finally store a[2] row, each row of four elements is also stored in turn. Array A is of type int, each element occupies 4 bytes, and the entire array occupies 4x (3x4) = 48 bytes.
If we do the second question, 99 multiplication table, the number of arrays to be increased by 1, otherwise there is no way to calculate the 9*9, column:
#include <stdio.h>intMain () {inti,j; inta[Ten][Ten]; for(i=0; i<=9; i++) for(j=1; j<=i;j++) A[i][j]=i*J; for(i=0; i<=9; i++){ for(j=1; j<=i;j++) printf ("%2d*%d=%2d", J,i,a[i][j]); printf ("\ n"); } return 0;}
If written a[9][9], the back will be all garbled, only a little more will be counted intact.
Experimental experience: two-dimensional arrays can be thought of as a one-dimensional array nested, the one-dimensional array of each element as an array, the formation of a two-dimensional array. Of course, the premise is that each element type must be the same, according to such analysis, a two-dimensional array can also be decomposed into multiple one-dimensional arrays.
Future estimates will be more difficult, I hope I can refuel hard to learn!!!
Application of Experiment 9:2-D array and character array