Advertisement

simple stuff, I just forgot

Started by November 10, 2000 06:28 PM
4 comments, last by CHollman82 24 years, 2 months ago
could someone please refresh my memory on how to pass a multi-dimensional array to a function as a referance parameter (C++) thanx
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();
Uhh, I''d just pass a pointer to the array. You can easily access all the array elements (even in a multidimensional array) through the pointer. I was taught early on that it''s generally a bad idea to send an array, especially a multidimensional array to a function as it will then push the entire array onto the stack. Not to metion it''s just bad form, and real programmers will make fun of you I''m still a relatively new programmer, so I could be wrong.
Advertisement
you mean
int** &Array2DReference
?
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
OK, here we go....

int nums [3][4];

int *pnum;

pnum=#//OK this points to index nums[0][0]


void doit(int *pnum)
{
cout<<*pnum[2][1];//Print the value at nums[2][1]
}

You can access any value in the array by indexing it like a standard array. You can go further and just make the array a pointer in the first place.

int *nums [3][4];

Like I said though, I''m new, I could be wrong. Someone feel free to correct me
Pretty much. The reference I have says that

function(int a[]);

is the same as

function(int* a);
<span class="smallfont">That is not dead which can eternal lieAnd with strange aeons even death may die.   -- "The Nameless City" - H. P. Lovecraft</span>
thanks for the help everyone.
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();

This topic is closed to new replies.

Advertisement