Passing an entry from an array as argument
-
Can you pass an entry from the middle of the array as argument to a function?
void AFunction(int * ArrayItem, int size)
{}
int TestArray[5];
AFunction(&TestArray[3], 5); -
Can you pass an entry from the middle of the array as argument to a function?
void AFunction(int * ArrayItem, int size)
{}
int TestArray[5];
AFunction(&TestArray[3], 5);Sure, as a pointer to that element (
&array[i]
) or as a reference (array[i]
). This is assuming you want access to the actual element, not a copy. If it's an array ofint
, the receiving arguments would have the typesint*
andint&
, respectively.Robust Services Core | Software Techniques for Lemmings | Articles
-
Sure, as a pointer to that element (
&array[i]
) or as a reference (array[i]
). This is assuming you want access to the actual element, not a copy. If it's an array ofint
, the receiving arguments would have the typesint*
andint&
, respectively.Robust Services Core | Software Techniques for Lemmings | Articles
What are the constraints? do you have access to other elements in the array in this situation? the function body in my example code is not defined because I`m not certain how it should look like.
-
What are the constraints? do you have access to other elements in the array in this situation? the function body in my example code is not defined because I`m not certain how it should look like.
No, this only gives you access to the element that you pass in. If you want access to all of them, pass the array itself (I seem to remember a previous thread about how to do that) and use the index operator.
Robust Services Core | Software Techniques for Lemmings | Articles
-
No, this only gives you access to the element that you pass in. If you want access to all of them, pass the array itself (I seem to remember a previous thread about how to do that) and use the index operator.
Robust Services Core | Software Techniques for Lemmings | Articles
Thanks Greg