#include <iostream>
usingnamespace std;
int *ReverseArray(int *orig, int b)
{
int swap;
int c = -1;
for(int a=-4; a < -2; a++)
{
swap = orig[a];
orig[a]=orig[c];
orig[c]=swap;
c--;
}
return orig;
}
int main()
{
constunsignedshortint SIZE = 2;
int ARRAY[SIZE][SIZE] = {{1,2},{3,4}};
int *arr = ARRAY[SIZE];
for(int i = 0; i < 2 * SIZE; i++)
cout << arr[i-2*SIZE] << " ";
cout << std::endl << endl;
arr = ReverseArray(arr, SIZE);
cout << endl;
for(int i = 0; i < 2 * SIZE; i++)
std::cout << arr[i- 2 * SIZE] << " ";
cout << std::endl;
return 0;
}
I managed to cobble this program together, it works as intended, however in a certan segment:
1 2 3 4 5 6
constunsignedshortint SIZE = 2;
int ARRAY[SIZE][SIZE] = {{1,2},{3,4}};
int *arr = ARRAY[SIZE];
for(int i = 0; i < 2 * SIZE; i++)
cout << arr[i-2*SIZE] << " ";
by messing around with it I found the only way I could get it to work was to offset arr[] by the number of items in my multidimensional array, in this case four. The program compiles, but I don't want to go through the rest of my life offsetting all my multidimensioanl array pointers by the size of the array. Could someone post the correct syntax for pointing to/passing a multidimensional array by reference? Thanks.