English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

void create2(unsigned int size, double **array_head)
{
*array_head = new double[size];
}

2006-10-28 22:20:28 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

Assuming you had allocated any space in array_head, the statement
*array_head = new double[size] would be creating an array and storing its address at a wrong location.
Since you are using a double pointer - i assume you would like to create a 2D array. Instead of the code you have provided try the following:-
/************************/
void create2( unsigned int rowSize, unsigned int colSize, double **array_head )
{

array_head = new double *[ rowSize ];

for( int rowIndex = 0; rowIndex < rowSize; rowIndex++)
array_head[ rowIndex ] = new double[ colSize ];

}
/************************/

2006-11-01 19:45:19 · answer #1 · answered by mashiur1973 2 · 1 0

Nothing wrong here, at the compilation time. But at the run time it may cause problem, in accessing array_head. array_head looks like a two dimensional array of doubles, and you have only mentioned the size for one dimension. How will you go about other dimension?

2006-10-29 00:30:59 · answer #2 · answered by manoj Ransing 3 · 1 0

I`ll say there is, throw your keypad out.

2006-10-28 22:24:04 · answer #3 · answered by Sentinel 7 · 0 0

Its correct if you correct some of your spellings.

2006-10-28 22:24:36 · answer #4 · answered by Achilles 2 · 0 0

fedest.com, questions and answers