# Dynamically allocated matrices

• 10-27-2001
Unregistered
Dynamically allocated matrices
can anyone please reply with some code to allocate arrays on the free store, like this (but than one that can compile..):
int * a;
a = new int[100][100];

do you get what I mean?
• 10-27-2001
Stoned_Coder
if you consider that a 2d array is really only an 1d array of 1d arrays then im sure you will see the answer!
• 10-27-2001
Unregistered
cool nick :)

hmm I'm probably kind of an idiot, all I can think of is:

int **a;
for(int b=0;b<10;b++)
{
a[b] = new int[10];
for(int c=0;c<10;c++)
a[b][c] = new int;
}

and that gives a runtime error
• 10-27-2001
Unregistered
Quote:

Originally posted by Unregistered
[B]cool nick :)

hmm I'm probably kind of an idiot, all I can think of is:

int ***a;
for(int b=0;b<10;b++)
{
a[b] = new int*[10];
for(int c=0;c<10;c++)
a[c] = new int;
}

and that gives a runtime error

this is what I meant..
• 10-27-2001
The V.
Code:

``` int ** matrix = new int*[a]; for (int i = 0; i < a; i++){         matrix[a] = new int[b]; } . . . for (int i = 0; i < a; i++){         delete[] matrix[a]; } delete[] matrix;```
• 10-27-2001
Unregistered
thanks !