# use pointer notation when passing multidimensional arrays?

Printable View

• 11-04-2001
gogo
use pointer notation when passing multidimensional arrays?
Hi,

Anyone could help me how to use pointer notation when passing multidimensional arrays?

I got an error C2664: 'yield' : cannot convert parameter 1 from 'double [3][4]' to 'double *[][4]' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast. I am using MS Visual C++ Compiler.

#include <iostream>
using namespace std;

double yield(double* hello[][4], int x);

double array[3][4] = {
{1.5, 2.6, 4.2, 4.3},
{7.3, 6.2, 9.7, 5.2},
{1.3, 8.5, 9.7, 4.8}
};

int main()
{
cout << "Total = " << yield(array, sizeof array / sizeof array[0]) <<endl;
return 0;
}

double yield(double* values[][4], int count)
{
double sum = 0.0;
for (int i=0; i < count ; i++)
for(int j=0; j<4; j++)
sum += *values[i][j];
return sum;
}

Thank in advance.

gogo
:o
• 11-04-2001
guest
In the code you posted array is a 2 dimensional array whereas the first parameter in your function:

double* hello[][4]

is a three dimensional array. You should use either:

double hello[][4],

or

double * hello[4],

or

double ** hello,

as the first parameter. Each of the above can be thought of as two dimensional arrays.
• 11-04-2001
Salem
> double array[3][4]
If this is your start point, then these are valid prototypes.

double yield ( double values[3][4], int count );
double yield ( double values[][4], int count );
double yield ( double (*values)[4], int count );
• 11-04-2001
Brown Drake
An array name is an implicit pointer to the first element of the array. An array element is a variable. In pointer terms, an array element would be like pointer arithmetic. At least that's my understanding.
• 11-05-2001
gogo
Thanks a lot.

All work now.

gogo