本人新手,想研究一些问题,于是写了以下代码:
# include <stdio.h>
void f(int * pAzz, int len, int high)
{
int i, j;
for (i=0; i<len; ++i)
{
for (j=0; j<high; ++j)
printf("%d ", *(pAzz + i + j) );
}
}
int main(void)
{
int a[2][3] = {{1, 2, 3}, {4, 5, 6}};
f(a, 2, 3);
printf("\n");
return 0;
}
结果报错了,代码如下:
--------------------Configuration: 确定二维数组的存储方式 - Win32 Debug--------------------Compiling...确定二维数组的存储方式.cpp
E:\111\资料\C\练习\确定二维数组的存储方式.cpp(20) :
error C2664: 'f' : cannot convert parameter 1 from 'int [2][3]' to 'int *'
Types pointed to are unrelated; conversion requires reinterpret_cast,
C-style cast or function-style cast
执行 cl.exe 时出错.
确定二维数组的存储方式.obj - 1 error(s), 0 warning(s)
# include <stdio.h>
void f(int * pAzz, int len, int high)
{
int i, j;
for (i=0; i<len; ++i)
{
for (j=0; j<high; ++j)
printf("%d ", *(pAzz + i + j) );
}
}
int main(void)
{
int a[2][3] = {{1, 2, 3}, {4, 5, 6}};
f(a, 2, 3);
printf("\n");
return 0;
}
结果报错了,代码如下:
--------------------Configuration: 确定二维数组的存储方式 - Win32 Debug--------------------Compiling...确定二维数组的存储方式.cpp
E:\111\资料\C\练习\确定二维数组的存储方式.cpp(20) :
error C2664: 'f' : cannot convert parameter 1 from 'int [2][3]' to 'int *'
Types pointed to are unrelated; conversion requires reinterpret_cast,
C-style cast or function-style cast
执行 cl.exe 时出错.
确定二维数组的存储方式.obj - 1 error(s), 0 warning(s)