Is there a way to pass a 2d array to a function without the function knowing how many elements each row has?
If not, i'm interested about what does "inverting" a 2d array means?
Replacing first row with the last one, etc?
Anyway, this is the code.
Code:
#include <iostream>
using namespace std;
void invert(char array[][3])
{
size_t rows = sizeof(array) / sizeof(array[0]);
size_t columns = sizeof(array[0]);
for(int i = 0, k = rows; i < rows; i++, k--)
for(int j = 0; j < columns; j++) {
char temp = array[i][j];
array[i][j] = array[k][j];
array[k][j] = temp;
}
}
int main()
{
char array[2][3] = { 'd', 'a', 'e', 'l', 'o', 'm' };
cout << sizeof(array) << endl;
cout << sizeof(array[0]) << endl;
invert(array);
for(int i = 0; i < 2; i++)
for(int j = 0; j < 3; j++)
cout << array[i][j];
return 0;
}