How to pass a pointer to an array by reference?

Mar 14, 2013 at 4:40am
I have a struct which has an array inside of it:

1
2
3
4
struct someStruct{
int structArray[999];

}


Now when I want to access that array, I have the following:

ptrSomeStruct->structArray[someIndex];

But now I want to pass structArray to this function by reference so that it can adjust the array as needed and I can continue to use the array back in my caller function:

void adjustArray(void *& someArray){}

How do I accomplish this?
Mar 14, 2013 at 5:20am
You can use something like the following:

void adjustArray(int (&someArray)[999]) {}

Mar 14, 2013 at 10:36am
The type of object you want to pass into the function is an array of integers, or a pointer to an integer. It's perfectly legal to have a reference to a pointer, so your function prototype would be:

void adjustArray(int*& someArray) {}

Yeah, the mixture of * and & symbols looks a bit messy, but it's perfectly fine.
Last edited on Mar 14, 2013 at 10:37am
Topic archived. No new replies allowed.