By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,512 Members | 1,711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,512 IT Pros & Developers. It's quick & easy.

Passing a 2 dimensional array to a Function

P: n/a
Hai,
I am trying to pass a 2 dimensional array to a function and I am having
a problem with this.
If the array was a Static 2D array, the code would be somethinlike this

void displayArray(myArray[][10],int rowSize)

If it is a Dynamic array, the number 10 for the second dimension cannot
be mentioned and I dont know a workaround. Please let me know asap.

Thank You,
Poojitha.

Nov 11 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Your function would look something like this:

void displayArray(int** array, int numCols, int numRows);

you just tell it how many rows and columns are in the array.

Nov 11 '05 #2

P: n/a
po***********@gmail.com wrote:
Hai,
I am trying to pass a 2 dimensional array to a function and I am having
a problem with this.
If the array was a Static 2D array, the code would be somethinlike this

void displayArray(myArray[][10],int rowSize)

If it is a Dynamic array, the number 10 for the second dimension cannot
be mentioned and I dont know a workaround. Please let me know asap.

Thank You,
Poojitha.


Normally this

void displayArray(int **myArray, int rowSize, int colSize)

but really it depends on how you have created your 2D dynamic array. Why
not post the code you have written.

john
Nov 11 '05 #3

P: n/a
po***********@gmail.com wrote:
Hai,
I am trying to pass a 2 dimensional array to a function and I am having
a problem with this.
If the array was a Static 2D array, the code would be somethinlike this

void displayArray(myArray[][10],int rowSize)

If it is a Dynamic array, the number 10 for the second dimension cannot
be mentioned and I dont know a workaround. Please let me know asap.


Use 'vector<vector<whatever> >'

V
Nov 11 '05 #4

P: n/a
po***********@gmail.com wrote:
...
I am trying to pass a 2 dimensional array to a function and I am having
a problem with this.
If the array was a Static 2D array, the code would be somethinlike this

void displayArray(myArray[][10],int rowSize)

If it is a Dynamic array, the number 10 for the second dimension cannot
be mentioned and I dont know a workaround. Please let me know asap.
...


C++ does not have a core language data type, which would immediately represent a
2D array with flexible second dimension. This means that in order to represent
your 2D array you must be using a library- or user-defined data structure. The
answer to your question heavily depends on what you are actually using. Post
more details.

--
Best regards,
Andrey Tarasevich
Nov 11 '05 #5

P: n/a

Victor Bazarov wrote:
po***********@gmail.com wrote:
Hai,
I am trying to pass a 2 dimensional array to a function and I am having
a problem with this.
If the array was a Static 2D array, the code would be somethinlike this

void displayArray(myArray[][10],int rowSize)

If it is a Dynamic array, the number 10 for the second dimension cannot
be mentioned and I dont know a workaround. Please let me know asap.


Use 'vector<vector<whatever> >'

V


under NO circumstances use 'vector<vector<whatever> >'
but rather 'vector<vector<whatever> >& '

Nov 11 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.