int** DATA = new int*[10];
DATA[0] = new int[100]; //works
DATA[1] = new int[100][5]; //dont work
DATA[1][100] = 1;
hello, i'm trying to create a jagged array, but need 5 columns. thanks
int** DATA = new int*[10];
DATA[0] = new int[100]; //works
DATA[1] = new int[100][5]; //dont work
DATA[1][100] = 1;
hello, i'm trying to create a jagged array, but need 5 columns. thanks
Do you really need a jagged array (different number of columns for each row) or just a two dimensional array, with 5 columns for each row. In both cases Ulrich's advice to prefer std::vector over bare arrays is good, and you should consider it.
However if you absolutely require a two dimensional array created in C-style, the way to do it is
int** p = new int*[10];
for( int i=0; i<10; i++ ) {
p[i] = new int[20];
}
p[7][17] = 177;
This will create a 2D array with 10 rows and 20 columns that can be accessed using 2D array syntax.