Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2-D arrays

Status
Not open for further replies.

DigitalOx

Programmer
Sep 29, 1998
41
US
I can't seem to pass a 2-D array into a funciton properly. <br>
<br>
//These methods don't work <br>
int myarray[1][1] = {1, 1};<br>
void myfunction1(int thearray[]);<br>
void myfunction2(int thearray[][]);<br>
void myfunction3(int *thearray);<br>
<br>
None of these methods work. What to do?<br>
<br>
Thanks,<br>
Scott
 
I'm learning on Borland but to pass a 2D array, it seems that the function needs to know the size of the second dimension - something like this<br>
<br>
void myfunction(int thearray[][maxsize])<br>
<br>
it's suggested that you use typedef to define the array types so your actual and formal parameters match exactly -- just getting this out of a book - haven't tried it yet
 
I don't think you need to pass the array from function to function. You can pass by reference and still change any part of the array from outside of the function that the array resides in.<br>
<br>
There are two operators that accomplish this in different ways depending on what you are trying to accomplish. Use either the (.) dot or the(-&gt;) struct pointer operator to reference the point in the array you want to change.<br>
<br>
You can use scoping and then use the scope operator :):) to point to your array. This method would also eliminate the need to pass any pointers at all within your entire program, depending on the complexity of course.<br>
<br>
Any of these methods may require you to make other changes to your code structure to make them execute properly, but I am just tossing out ideas as an answer to your question.
 
Thanks yall. Interesting idea using the scope op. I'll have tto read up on that one.<br>
DigitalOx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top