everyone.
I use Visual Studio 2013 (C++) and defined a 2d array in main function:
int _tmain(int argc, char **argv)
{
int g[3][3] = { { 1, 2, 3, }, { 4, 5, 6, }, { 7, 8, 9, }, };
...
return 0;
}
then, I defined a function in Define 1:
Define 1:
void print_array(int **arr, int kx, int ky)
{
for (int i = 0; i < kx; i++) {
for (int j = 0; j < ky; j++) {
printf("%d ", arr[i][j]);
}
printf("\n");
}
}
I want to call this function from main function:
int _tmain(int argc, char **argv)
{
int g[3][3] = { { 1, 2, 3, }, { 4, 5, 6, }, { 7, 8, 9, }, };
print_array(g, 3, 3);
return 0;
}
The visual studio tells me that:
Error 1 error C2664: 'void print_array(int **,int,int)' : cannot convert argument 1 from 'int [3][3]' to 'int **'
I also know another definition method:
Define 2
void print_array(int (*arr)[3], int kx, int ky)
{
for (int i = 0; i < kx; i++) {
for (int j = 0; j < ky; j++) {
printf("%d ", arr[i][j]);
}
printf("\n");
}
}
Now it works.
My question is: I remenbered before that they (Define 1 and Define 2) worked both in old compiler, named you can pass array name as int **
or int (*p) []
correctly to another function. However in Visual Studio C++ it is not. Is Visual Studio C++ much stricter than other compiler ? Or I did something wrong?
Thank you very much!