为什么会出现 can't convert paremeter 1 from 'int *' to 'int [][4]' ?
用指向二维数组的指针作函数的参数,实现对二维数组的按行相加:程序如下
#include<stdio.h>
#define M 3
#define N 4
main()
{
int arr[M][N];
int i,j,score1,score2,score3,*p=arr[0];
void fun( int b[][N],int *p1,int *p2,int *p3);
for (i=0;i<M;i++)
for (j=0;j<N;j++)
scanf("%d",&arr[i][j]);
fun(p,&score1,&score2,&score3);
printf("%d,%d,%d",score1,score2,score3);
return 0;
}
void fun( int b[][N],int *p1,int *p2,int *p3)
{
int i,j;
if(i==0) *p1=*p1+b[i][j];
if(i==1) *p2=*p2+b[i][j];
if(i==2) *p3=*p3+b[i][j];
}
程序调用fun函数时,怎么出现can't convert paremeter 1 from 'int *' to 'int [][4]' 的提示错误,高了半天还是不明白, 请问我的程序究竟哪儿出错了, 指针部分真的不大好学阿。哪位大哥大姐帮忙解答一下。 谢谢!!
问题点数:20、回复次数:7Top
1 楼David888david()回复于 2004-12-02 10:07:47 得分 4
int **p = arr[0];
不应该int *p = arr[0]Top
2 楼iicup(双杯献酒)回复于 2004-12-02 10:10:55 得分 4
fun的第一个参数应该是指向"整数数组"的指针,
但 p 是 指向“整数”的指针。
所以类型不匹配.Top
3 楼260005065(宁独遗与世,亦当皓首穷经,但有所得,无悔无怨。)回复于 2004-12-02 10:11:13 得分 4
先不管你程序是做什么?
就语法来说:
int i,j,score1,score2,score3,*p=arr[0];
改为
int i,j,score1,score2,score3,(*p)[N]=arr;Top
4 楼alanzhu(爱的逃兵)回复于 2004-12-02 10:11:46 得分 4
应该是 int **p = arr把,呵呵
Top
5 楼mathe()回复于 2004-12-02 10:14:05 得分 4
fun(arr,&score1,&score2,&score3);
或者
int (*p)[N] = arr;
fun(p,&score1,&score2,&score3);
或者
fun((int *[N])p,&score1,&score2,&score3);Top
6 楼260005065(宁独遗与世,亦当皓首穷经,但有所得,无悔无怨。)回复于 2004-12-02 10:19:42 得分 0
alanzhu(啊鸿)的想法混乱。
对于二维指针
**p和*p[N] (*p)[N]和p[M][N]
是分别匹配的.Top
7 楼johnyjin( ⊙ 右手工作,左手接money ¥ )回复于 2004-12-02 10:26:11 得分 0
经过大家的讨论问题解决了 还是对有关二维数组指针问题搞得不清楚,继续学习..... 谢谢各位: 接分哦! 讨论者都有分Top
相关问题
- how to convert CString to the int?
- how to convert CString to int
- how to convert time_t to int?
- how convert String to int?
- How to convert a int to unsigned char* ?
- How Can I convert a string to int
- How to convert int type to char type?? Such as 23 to {'2','3'}; Thanks
- 菜问:如何 convert from 'struct wParam' to 'unsigned int' ?
- 关于select * from Rcdjb order by convert(int,id) desc
- error C2440: 'specialization' : cannot convert from 'int (__stdcall *)(void *)' to ' (__stdcall *)()'




