I was trying to pass array of arrays to a function, but I am not getting correct results. I looked at [this SO post][1] for this purpose. I am not getting any warnings and I am using TDM GCC 64 compiler. What could be wrong with this code?
#include <stdio.h>
#include<inttypes.h>
void printArrayOfArrays(uint8_t numRows,uint8_t numColumns,int arraOfArray[][numColumns]);
int main(void)
{
int numRows, numColumns, rowCount, colCount, first[5][5];
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d", &numRows, &numColumns);
printf("Enter the elements of first matrix\n");
for (rowCount = 0; rowCount < numRows; rowCount++)
{
for (colCount = 0; colCount < numColumns; colCount++)
{
scanf("%d", &first[rowCount][colCount]);
}
}
for (rowCount = 0; rowCount < numRows; rowCount++)
{
for (colCount = 0 ; colCount < numColumns; colCount++)
{
printf("%d\t",first[rowCount][colCount]);
}
printf("\n\n");
}
printf("\n");
printArrayOfArrays(numRows,numColumns,first);
return(0);
}
void printArrayOfArrays(uint8_t numRows,uint8_t numColumns,int arrayOfArray[numRows][numColumns])
{
for (uint8_t rowCount = 0; rowCount < numRows; rowCount++)
{
for (uint8_t colCount = 0 ; colCount < numColumns; colCount++)
{
printf("%d\t", *(*(arrayOfArray+rowCount)+colCount));
}
printf("\n");
}
}
The result I am getting for this is
Enter the number of rows and columns of matrix
2
2
Enter the elements of first matrix
4
3
1
6
4 3
1 6
4 3
0 0