C语言数组的溢出,c - C语言数组问题 - 堆栈内存溢出

嗨,我是C语言的新手,我遇到了一个问题:我想通过指针将2-d数组发送给函数。 该函数应返回指向二维数组的指针。 我为此编写了以下代码:

#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;

}

当我感到满意时,出现以下错误:

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数组

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值