How do i pass arrays into functions?
Yeah, very ''nubletish'' question, but my 21 day book didn''t explain it cause arrays were way after functions. I have a two dimensional array bUsed[4][4] and i wanna put it into a function PrintValues(). What''s the passing type, what exactly do i pass in, please help.
-----------------------------------------------------------
Like a sponge!
If you know the size of the array when writing the code you could do:
void func(bool bArray[4][4])
{
...
}
If not, I suggest using pointer to pointer to your datatype, like this:
void func(bool **bArray)
{
...
}
"For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!"
"If anyone sees a suspicious, camouflaged factory being carried across the desert, they should report it immediately."
void func(bool bArray[4][4])
{
...
}
If not, I suggest using pointer to pointer to your datatype, like this:
void func(bool **bArray)
{
...
}
"For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!"
"If anyone sees a suspicious, camouflaged factory being carried across the desert, they should report it immediately."
Awesome, got it. My problem was really elseware but i got it all figured out. Thanks.
-----------------------------------------------------------
Like a sponge!
-----------------------------------------------------------
Like a sponge!
quote:Original post by Valderman
If you know the size of the array when writing the code you could do:
void func(bool bArray[4][4])
{
...
}
If not, I suggest using pointer to pointer to your datatype, like this:
void func(bool **bArray)
{
...
}
<hr size=1><font size=1>"For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!"
"If anyone sees a suspicious, camouflaged factory being carried across the desert, they should report it immediately ."</font>
uh don''t do that.
int temp[5][5] is not int**, its an int*.
look up passing by reference, to save memory. something like this:
void func(int* &array)
My Homepage
void func(int* &array)
My Homepage
quote:int temp[5][5] is not int**, its an int*.
Nope.
void func(char **c){ printf("%c", c[0][0]);}
...compiles nicely, while...
void func(char *c){ printf("%c", c[0][0]);}
...gives a "subscript requires array or pointer type".
"For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!"
"If anyone sees a suspicious, camouflaged factory being carried across the desert, they should report it immediately."
Julio wrote
"look up passing by reference, to save memory. something like this:
void func(int* &array) "
Assuming we are talking about c++ here (since you used a reference), how does this save memory over
void func(int* array)
or
void func(int array[5])
?
I don''t see that it saves anything?
"look up passing by reference, to save memory. something like this:
void func(int* &array) "
Assuming we are talking about c++ here (since you used a reference), how does this save memory over
void func(int* array)
or
void func(int array[5])
?
I don''t see that it saves anything?
i dont know if you can...well...u can...but i dont think that that particulay function is gonna cut it....you can always loop it
take my include files for granted
int main()
{
int x=1, y=1;
while (x<=4||y<=4)
{
cout<
x++;
if (x==4)
{
x=0;
y++;
}
}
return 0;
}
didnt check it at all.....but yah...it might help a bit
take my include files for granted
int main()
{
int x=1, y=1;
while (x<=4||y<=4)
{
cout<
x++;
if (x==4)
{
x=0;
y++;
}
}
return 0;
}
didnt check it at all.....but yah...it might help a bit
Put that in [ source ] tags, it's pretty unreadable in its current state.
"For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!"
"If anyone sees a suspicious, camouflaged factory being carried across the desert, they should report it immediately ."
[edited by - Valderman on July 6, 2003 10:22:57 PM]
"For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!"
"If anyone sees a suspicious, camouflaged factory being carried across the desert, they should report it immediately ."
[edited by - Valderman on July 6, 2003 10:22:57 PM]
quote:Original post by Julio
look up passing by reference, to save memory. something like this:
void func(int* &array)
Either one passes a 32-bit pointer.. i don''t see how you''re saving anything...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement