#include <stdio.h>
void printarray(const int arr[][3]);
int main()
{
int arr[][3] = {{1,2,3},{4,5,6}};
printarray(arr);
getchar();
return 0;
}
void printarray(const int arr[][3])
{
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
printf("%d\t", arr[i][j]);
printf("\n");
}
}
This above code tends to give me a warning.
9 D:\cprogramming\arr1.c [Warning] passing argument 1 of 'printarray' from incompatible pointer type
but if i specify the arr in the main as const everything goes well.
But the same code with just 1D array it dons't tend to give me any warning, i dont understand why?
#include <stdio.h>
void printarray(const int arr[]);
int main()
{
int arr[] = {1,2,3,4,5,6};
printarray(arr);
getchar();
return 0;
}
void printarray(const int arr[])
{
int i;
for(i=0;i<6;i++)
printf("%d\t", arr[i]);
}
Can anyone please explain why?
ssharish