c语言数组void,c语言数组问题

嗨 我是新来的c语言我有一个问题: 我想通过指针发送一个二维数组到一个函数。 该函数应该返回指向二维数组的指针。 我写了这以下代码:c语言数组问题

#include

int* put(int *b);

int main()

{

int a[2][3],i,j;

system("clear");

put(a);

for(i=0;i<2;i++)

{

for(j=0;j<3;j++)

{

printf("\na[%d][%d]= %d",i,j,a[i][j]);

}

}

return 0;

}

int* put(int *b)

{

for(i=0;i<2;i++)

{

for(j=0;j<3;j++)

{

b[i][j]=i;

}

}

return b;

}

当我与gcc2de.c编译它显示了以下错误:

2de.c: In function ‘main’:

2de.c:9: warning: passing argument 1 of ‘put’ from incompatible pointer type

2de.c:3: note: expected ‘int *’ but argument is of type ‘int (*)[3]’

2de.c: In function ‘put’:

2de.c:28: error: subscripted value is neither array nor pointer

2de.c: In function ‘main’:

2de.c:32: error: expected declaration or statement at end of input

比我只是改变的函数的代码这是继:

#include

int* put(int **b);

int main()

{

int a[2][3],i,j;

system("clear");

put(a);

for(i=0;i<2;i++)

{

for(j=0;j<3;j++)

{

printf("\na[%d][%d]= %d",i,j,a[i][j]);

}

}

return 0;

}

int* put(int **b)

{

for(i=0;i<2;i++)

{

for(j=0;j<3;j++)

{

b[i][j]=i;

}

}

return b;

}

当我complie它,我得到了以下错误:

2de.c: In function ‘main’:

2de.c:9: warning: passing argument 1 of ‘put’ from incompatible pointer type

2de.c:3: note: expected ‘int **’ but argument is of type ‘int (*)[3]’

2de.c: In function ‘put’:

2de.c:31: warning: return from incompatible pointer type

2de.c: In function ‘main’:

2de.c:32: error: expected declaration or statement at end of input

2de.c: In function ‘main’:

2de.c:9: warning: passing argument 1 of ‘put’ from incompatible pointer type

2de.c:3: note: expected ‘int **’ but argument is of type ‘int (*)[3]’

2de.c: In function ‘put’:

2de.c:31: warning: return from incompatible pointer type

2de.c: In function ‘main’:

2de.c:32: error: expected declaration or statement at end of input

我做错了什么? 任何人都可以告诉我什么是通过指针传递2d数组的方式? 任何人都可以告诉我如何通过函数中的指针返回两个d数组

+0

在'printf(“\ na [%d] [%d] =%d”,i,j,a [i] [j])之后会出现'}';',防止编译。 –

2011-05-02 07:53:12

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值