Method one: Use array pointers to open space with new
<span style= "FONT-SIZE:18PX;" > #include <iostream>using namespace std; #define ROW 3#define COL 4void main () {int (*p) [COL] = new Int[row][col]; for (int i=0, i<row; ++i) {for (int j=0; j<col; ++j) {p[i][j] = i+j;}} For (i=0, i<row; ++i) {for (int j=0; j<col; ++j) {cout<<p[i][j]<< "";} Cout<<endl;} delete []p;} </span>
Method Two: Using the C language method. For example, with:
The code is as follows:
#include <iostream>using namespace std; #define ROW 3#define COL 4void main () {int **p = (int * *) malloc (sizeof (int*) *r OW); for (int i=0; i<row; ++i) {p[i] = (int *) malloc (sizeof (int) * COL);} For (i=0, i<row; ++i) {for (int j=0; j<col; ++j) {p[i][j] = i+j;}} For (i=0, i<row; ++i) {for (int j=0; j<col; ++j) {cout<<p[i][j]<< "";} Cout<<endl;} For (i=0, i<row; ++i) {free (p[i]); Delete []p[i]}free (p); delete []p;}
Code there is not comprehensive place I hope you can point out ~ Thank you ~
Creation of two-dimensional arrays