C语言问题 cannot convert parameter 1 from 'int' to 'int [][4]' C语言新手,望高手解答
#include<stdio.h>intfind_max(inta[5][4],intb[5],int*p1){inti,j,k,t;for(i=0;i<6;++i){f...
#include<stdio.h>
int find_max(int a[5][4],int b[5],int *p1)
{
int i,j,k,t;
for(i=0;i<6;++i)
{for(j=1,k=a[i][0];j<5;++j)
k=k+a[i][j];
b[i]=k/5;}
for(i=0,j=1;j<6;++j)
{if(b[i]>b[j])
k=i;
else {t=b[j];b[j]=b[i];b[i]=t;}
}
p1=&b[i];
return(*p1);
}
int main()
{
int find_max(int a[5][4],int b[5],int *p1);
int a[5][4]={{1,2,3,4},{2,3,4,5},{3,4,5,6},{4,5,6,7},{5,6,7,8}},b[5],y;
int *p1;
y=find_max(a[5][4],b[5],*p1);
printf("%d",y);
return 0;
}
lianxi2.cpp
C:\Documents and Settings\Administrator\桌面\lianxi2.cpp(24) : error C2664: 'find_max' : cannot convert parameter 1 from 'int' to 'int [][4]'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.
lianxi2.exe - 1 error(s), 0 warning(s)
请把错误原因稍微详细一点的告知 展开
int find_max(int a[5][4],int b[5],int *p1)
{
int i,j,k,t;
for(i=0;i<6;++i)
{for(j=1,k=a[i][0];j<5;++j)
k=k+a[i][j];
b[i]=k/5;}
for(i=0,j=1;j<6;++j)
{if(b[i]>b[j])
k=i;
else {t=b[j];b[j]=b[i];b[i]=t;}
}
p1=&b[i];
return(*p1);
}
int main()
{
int find_max(int a[5][4],int b[5],int *p1);
int a[5][4]={{1,2,3,4},{2,3,4,5},{3,4,5,6},{4,5,6,7},{5,6,7,8}},b[5],y;
int *p1;
y=find_max(a[5][4],b[5],*p1);
printf("%d",y);
return 0;
}
lianxi2.cpp
C:\Documents and Settings\Administrator\桌面\lianxi2.cpp(24) : error C2664: 'find_max' : cannot convert parameter 1 from 'int' to 'int [][4]'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.
lianxi2.exe - 1 error(s), 0 warning(s)
请把错误原因稍微详细一点的告知 展开
展开全部
#include<stdio.h>
int find_max(int a[5][4],int b[5],int *p1)
{
int i,j,k,t;
for(i=0;i<6;++i)
{for(j=1,k=a[i][0];j<5;++j)
k=k+a[i][j];
b[i]=k/5;}
for(i=0,j=1;j<6;++j)
{if(b[i]>b[j])
k=i;
else {t=b[j];b[j]=b[i];b[i]=t;}
}
p1=&b[i];
return(*p1);
}
int main()
{
int find_max(int a[5][4],int b[5],int *p1);
int a[5][4]={{1,2,3,4},{2,3,4,5},{3,4,5,6},{4,5,6,7},{5,6,7,8}},b[5],y;
int *p1;
y=find_max(a,b,p1); //实参和虚参要对应a[5][4]这是一个元素
printf("%d ",y);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询