I am trying to make a function that prints out two dimensional arrays. I did one that prints out 1d arrays.
#include <iostream>
using namespace std;
void printArray (int theArray[],int sizeOfArray);
int main ()
{
int array1[3] = {1,3,7};
int array2[5] = {123,5,23,2,324};
printArray(array1, 3);
printArray(array2, 5);
}
void printArray (int theArray[],int sizeOfArray){
for (int x=0; x<sizeOfArray; x++) {
cout<<theArray[x] <<" ";
}
cout<<endl;
}
I wrote these codes for printing out 2d arrays but I failed.
#include <iostream>
using namespace std;
void printArray (int theArray[][],int sizeOfRow, int sizeOfCol);
int main ()
{
int array[2][3] = {{1,3,7},{5,3,2}};
printArray(array, 2,3);
}
void printArray (int theArray[][],int sizeOfRow, int sizeOfCol){
for (int x=0; x<sizeOfRow; x++)
for (int y=0; y<sizeOfCol; y++) {
cout<<theArray[x][y] <<" ";
}
cout<<endl;
}
My compiler says array has incomplete element type 'int[]'. What are the right codes for printing out 2d arrays?