In C ++ Primer, there is no multi-dimensional array in C ++ and only an array of element division arrays.
For example, to create a two-dimensional integer array, you must first create a one-dimensional dynamic array, which consists of int * type pointers. Int * is the type of this one-dimensional int pointer array.
The following is an example
[Cpp]
// String. cpp: Defines the entry point for the console application.
//
# Include "stdafx. h"
# Include <iostream>
Typedef int * IntArrayPtr; // (1)
Void fill_array (int a [], int size );
Void sort (int a [], int size );
Int main (int argc, char * argv [])
{
Using namespace std;
Int row, col;
Cout <"Enter the row and column dimensions of the array: \ n ";
Cin> row> col;
IntArrayPtr * m; // (2)
Int I, j;
M = new IntArrayPtr [row];
// Apply for memory
For (I = 0; I <row; I ++)
M [I] = new int [col]; // m is now an array of row * col
Cout <"Enter" <row <"rows"
<Col <"integers each: \ n ";
/// Assign a value
For (I = 0; I <row; I ++)
For (j = 0; j <col; j ++)
Cin> m [I] [j];
/// Print a two-dimensional Dynamic Array
Cout <"Echoing the 2 dimetricarray: \ n ";
For (I = 0; I <row; I ++)
{
For (j = 0; j <col; j ++)
Cout <m [I] [j] <"";
Cout <endl;
}
/// Release the memory
For (I = 0; I <row; I ++)
Delete [] m [I];
Delete [] m;
Return 0;
}