473,394 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Passing a 2 dimensional array to a Function

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
5 11632
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
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
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: seemanta dutta | last post by:
greetings C gurus, I would be grateful if I could know the answers to 2 questions: 1. I want to know how to pass a 2-dimensional array to a function, say foo() and what will be its prototype...
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
3
by: Alex Munk | last post by:
I would like to be able to pass a 2-dimensional array to a function as a string parameter. In the called function I would like to be able to convert the string back into a 2-dimensional array....
4
by: entitledX | last post by:
Hi, I'm trying to use the HDF library to read a few HDF files that I need to process. The data in each file varies in rows, but the columns remain constant. Because of that, I had dynamically...
3
by: ZMan | last post by:
The following code won't compile with gcc version 3.4.2 (mingw-special). How come? Error: cannot convert `char (*)' to `char**' /**********************************************************/...
2
by: nleahcim | last post by:
Hi - I am working on writing a number of matrix manipulation functions. The most basic one was a printing algorithm - and it shows the problem I'm having. I'm passing it a pointer a mutidimensional...
4
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
5
by: nelly0 | last post by:
developing a program that will manipulate noise levels (measured in decibels) that is collected by car manufacturers. These noise levels are produced at seven different speeds by a maximum of six...
4
by: drktmplr11 | last post by:
Hi, this is my first post here at the forums, and I am looking for assistance with what looks to be a syntax error within my code. I am attending FIU, and looking to broaden my understanding of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.