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!
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!
int** array = 0;
// allocate first dimension
array = new int*[10]; // array of 10 pointers
Thank you very much!
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 )
>>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;
}
}
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.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.