1. The problem I am having is that I am trying to pass a two dimensional array from my main function to a secondary function. I know it has to be call by reference and using the name of the matrix, "matrix" in my case should send the location. Also since it has more than one dimension there needs to be an inclusion for the number of columns so the function declaration becomes:(adsbygoogle = window.adsbygoogle || []).push({});

float average_depth(float matrix[][6], int size);

where matrix is the matrix memory location, and int size is the total number of elements. From the two lines in my book about this and what I could find online this is the correct declaration for the pointer to the array. But I keep getting an error in the compiling. I have tried restarting Microsoft Visual Studio and reopening my code but it still does not work.

2. I have tried a number of things. Since the error code I keep on getting is an error code that says:

subscript requires array or pointer type

I think this means that I am not correctly passing the pointer, or possibly not using it correctly.

declaration:

float average_depth(float matrix[][6], int size);

call:

actualaverage=average_depth(matrix, 36);

function:

float average_depth(float matrix, int size)

{

float average;

for(int i=0;i<=size;i++)

{

average=average+matrix;

}

return average;

}

It is a six by six matrix so do I need to have size be 6 or 36. This is of course if I can figure out what is going wrong.

I have tried including the & operator and the * to force the passing of a pointer but that seemed to generate more errors. There is also a copy of the program if you want to look at it. I am sure it is something relatively simple but I have never used a pointer before and am sure that the finer points have been lost on me.

**Physics Forums - The Fusion of Science and Community**

# 2D Array passing is C++

Know someone interested in this topic? Share a link to this question via email,
Google+,
Twitter, or
Facebook

Have something to add?

- Similar discussions for: 2D Array passing is C++

Loading...

**Physics Forums - The Fusion of Science and Community**