I've just come across this program that deals with multidimensional arrays. While I've got the gyst of it, there's a particular notation that I'm not sure of.
The idea is to pass a pointer to the column of a multidimensional array, because 2-Dim arrays do not require you to mention the number of rows in the 2D matrix. So, a pointer pm to the column of the 2D matrix is passed as: int (*pm)[COLUMN]
Here's the full program:
#include<stdio.h>
#include<stdlib.h>
const int ROW = 2;
const int COL=3;
void fill_array(int (*pm)[COL], int row);
void display_array(int m[][COL], int row);
int main(int argc, char const *argv[])
{
/* code */
int i,j;
int m[ROW][COL];
//CALL function to enter elements
fill_array(m,ROW);
//display
display_array(m,ROW);
return 0;
}
void fill_array(int (*pm)[COL], int row)
{
int i,j;
printf("Please fill the array's content: \n");
for(i=0;i<row;i++)
{
for(j=0;j<COL;j++)
{
printf("\n m[%d][%d]: ",i,j);
scanf("%d", &pm[i][j]);
}
}
}
void display_array(int m[][COL], int row)
{
int i,j;
printf("\n Array's contents: \n");
for(i=0;i<row;i++)
{
for(j=0;j<COL;j++)
{
printf("%d\t", m[i][j]);
}
printf("\n");
}
}
I'm not sure about the representation of a pointer to an array. What I mean is I'm not familiar with this notation where a pointer is just appended to the array. Could someone please throw some light on this?
Many thanks!