alenscrist
Banned
- Joined
- January 21, 2010
- Messages
- 3
Hi Guys,
I have written the program for accesssing elements of 2D array using pointer to array of int which is as below:
void display(int (*)[4], int , int);
int main()
{
int a[2][4] = {{1,2,3,4},
{5,6,7,8}
};
display(a, 2, 4); // this line is giving error
getch();
}
void display(int (*ptr)[4], int row, int col)
{
int i, j;
int *p;
for(i = 0; i < row; i++)
{
p = ptr + i;
for( j= 0; j < col; j++)
{
printf("%d ", *(p+j));
}
printf("\n");
}
}
But the function declearion line is giving the error and also I am not sure about function prototype written correct or not.
Please help me in how the function prototype and declearation has to be written for the above fucntion defination.
Thanks
I have written the program for accesssing elements of 2D array using pointer to array of int which is as below:
void display(int (*)[4], int , int);
int main()
{
int a[2][4] = {{1,2,3,4},
{5,6,7,8}
};
display(a, 2, 4); // this line is giving error
getch();
}
void display(int (*ptr)[4], int row, int col)
{
int i, j;
int *p;
for(i = 0; i < row; i++)
{
p = ptr + i;
for( j= 0; j < col; j++)
{
printf("%d ", *(p+j));
}
printf("\n");
}
}
But the function declearion line is giving the error and also I am not sure about function prototype written correct or not.
Please help me in how the function prototype and declearation has to be written for the above fucntion defination.
Thanks
- Joined
- Jan 21, 2010
- Messages
- 3