Hi,

What is the dynamic array equivalent to this?

int *array[10]

---

int *array

array = new int[10]

I want something like the above, but I can't seem to figure out the correct way to do it

Any help would be appreciated!

Thanks!

vvtc
0
Newbie Poster

Hi,

What is the dynamic array equivalent to this?

int *array[10]

---

int *array

array = new int[10]

I want something like the above, but I can't seem to figure out the correct way to do it

Any help would be appreciated!

Thanks!

Jump to Post`int** array = 0; // allocate first dimension array = new int*[10]; // array of 10 pointers`

Jump to Post>>function(int *&head)

That is not a function that takes a 2d array. What you have there is a reference to a 1d array. They are not the same thing.`void functijon(int **array) { array[0][1] = 123; }`

The above is a 2 dimensional array of integers. The …

Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster

```
int** array = 0;
// allocate first dimension
array = new int*[10]; // array of 10 pointers
```

vvtc
0
Newbie Poster

Thank you very much!

vvtc
0
Newbie Poster

Ok, I'm stuck again. So if I have

```
int** array = 0;
// allocate first dimension
array = new int*[10]; // array of 10 pointers
```

How do I pass the array into function calls?

I have it as:

```
function( array[some_index] );
function(int *&head)
{
array = new int;
}
```

and it seems to work without and compilation errors, but it seems to me that whatever I do in the function to the array has no effect ( I passed it in by reference in the function call )

Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster

>>function(int *&head)

That is not a function that takes a 2d array. What you have there is a reference to a 1d array. They are not the same thing.

```
void functijon(int **array)
{
array[0][1] = 123;
}
```

The above is a 2 dimensional array of integers. The first dimension is an array of pointers. You still have to allocate the second dimension before the above will work

```
int main()
{
int **array;
array = new int*[10];
for(int i = 0; i < 10; i++)
{
array[i] = new int[20];
for(int j = 0; j < 20; j++)
array[i][j] = 0;
}
}
```

grumpier
149
Posting Whiz in Training

`void functijon(int **array) { array[0][1] = 123; }`

The above is a 2 dimensional array of integers.

Not really. array is a (misnamed) pointer to a pointer. It is not a 2D array. However, in some circumstances (eg the code example you gave, although I won't quote that again) a pointer to pointer can be treated as if it is a 2D array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.