Using pointers, how would you declare a dynamic double array to the effect of:
int matrix = new int[var][var];
where var is the size of the array.
??
Printable View
Using pointers, how would you declare a dynamic double array to the effect of:
int matrix = new int[var][var];
where var is the size of the array.
??
It's quite similar to what you do to unidimensional arrays. But with a slight "problem":
The problem as you can see is you can only specify the first dimension as a variable. All subsequent dimensions must be constants.Code:int* matrix=0;
//.. get the dimension from user input or processing (dim1)
if(!(matrix = new int[dim1][const]))
{
cout << endl
<< "Memory allocation failed.";
exit(1);
}
Also don't forget that no matter the number of dimensions, the delete statement only has one pair of square brackets:
delete [] matrix;
Yes... that was the problem I was facing. For anyone who's interested in the solution the answer is here:
http://www.cprogramming.com/cboard/s...c+double+array
He! I was finding it strange someone like you making such a simple question.
Sorry for misreading your question :)
No prob Mario, you helped me realize that conventional methods weren't going to work. My thanks.