An attempt to learn C ++ and work with a simple exercise on arrays.
Basically, I created a multidimensional array, and I want to create a function that outputs values.
The commented for-loop in Main () works fine, but when I try to turn this for-loop into a function, it will not work, and for life I donโt understand why.
#include <iostream>
using namespace std;
void printArray(int theArray[], int numberOfRows, int numberOfColumns);
int main()
{
int sally[2][3] = {{2,3,4},{8,9,10}};
printArray(sally,2,3);
}
void printArray(int theArray[], int numberOfRows, int numberOfColumns){
for(int x = 0; x < numberOfRows; x++){
for(int y = 0; y < numberOfColumns; y++){
cout << theArray[x][y] << " ";
}
cout << endl;
}
}
source
share