Two-dimensional array definitions:
General form: type specifier array name [constant expression 1][constant expression 2]
int a[2][3];
Using the C + + STL vector definition:
vector< vector<int> > Array (2, vector<int> (0)); Define the number of rows as 2
for (int i=0; i<2; i++)
Array[i].resize (3); Defines the number of columns as 3
Initialization of two-dimensional arrays:
Fragment assignment: int a[2[3]={{1, 2, 3},{4, 5, 6}}//row of constant expression can be omitted;
Continuous assignment: int a[2[3]={1, 2, 3, 4}//partial element assignment, followed by automatic assignment of 0
Parameter passing for two-dimensional arrays:
void Fun (int a[][3]) {...} Note that array a passes the parameter and then degenerates to a pointer
Dynamic allocation and release of two-dimensional arrays:
int **a=new int*[2];
for (int i=0; i<2; i++) {
A[i]=new Int[3];
}
////////////////////////////
for (int i=0; i<2; i++) {
Delete[] a[i];
}
Delete[] A;
Pointers to two-dimensional arrays:
int **p=a; Pointer P equals a
*p <=> a[0]; * (p+i) <=> a[i]; * (* (p+i) +j) <=> A[i][j]
Row and column calculations for two-dimensional arrays:
Total size: t=sizeof (a)/sizeof (A[0][0])
Number of columns: n=sizeof (a[0])/sizeof (a[0][0]); Array[0].size ()//vector type requires deep "inside" to find the size of the column
Number of rows: m=t/n; Array.size ()//vector type can directly find the size of the row
Two-dimensional arrays