Return array in a function

Hi all,

I have an array and a function. I want to return an array by using this function.

1
2
3
4
5
6
7
8
9
10
11
Function(int myArray[], int UpdateArray[])
{
    for(int t=0; t < NumElement; t++)
    {
       UpdateArray[t] = myArray[t];
    }

  swap(UpdateArray[0], UpdateArray[1]);

return UpdateArray;
}


Something like this. Is the syntax correct? Can I just say return UpdateArray?

Thanks in advance
you can do this:
1
2
3
4
5
6
7
8
void Function(const int myArray[], int UpdateArray[])
{
    for (int t = 0; t < NumElement; t++)
    {
        UpdateArray[t] = myArray[t];
    }
    swap(UpdateArray[0], UpdateArray[1]);
}

This will actually affect the original array, no need to return. The const in the first parameter tells us that this array will not be changed. The lack of a const in the second parameter tells us that it can be changed.
Topic archived. No new replies allowed.