Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Passing a 2 dimensional array to a Function

Reply
Thread Tools

Passing a 2 dimensional array to a Function

 
 
poojithareddy@gmail.com
Guest
Posts: n/a
 
      11-11-2005
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.

 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      11-11-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
jperalta17@gmail.com
Guest
Posts: n/a
 
      11-11-2005
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.

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      11-11-2005
(E-Mail Removed) 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
 
Reply With Quote
 
Andrey Tarasevich
Guest
Posts: n/a
 
      11-11-2005
(E-Mail Removed) 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
 
Reply With Quote
 
puzzlecracker
Guest
Posts: n/a
 
      11-11-2005

Victor Bazarov wrote:
> (E-Mail Removed) 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> >& '

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To convert a one dimensional array into a two dimensional array using C amrutha0303 Software 0 08-03-2010 10:02 PM
Why does passing two dimensional array to function accepting pointerto a pointer generate an error? Olumide C Programming 6 05-17-2010 03:36 PM
Passing a two dimensional array to function Sac C Programming 15 01-24-2009 06:42 AM
How do copy Strings from a single dimensional array to double dimensional array Venkat C++ 4 12-05-2003 09:23 AM
passing 2-Dimensional Array to a function seemanta dutta C Programming 1 08-08-2003 09:03 PM



Advertisments