如何用数组指针传值

皓月鸣心 2013-11-20 08:34:04
我想将数组a中的值传给数组b,但是实现不了,为什么啊?
#include <stdio.h>
fun(double*p)
{

double a[10]={0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0};
p=a;
return 0;
}

int main()
{
double b[10]={0.0};
fun(b);
printf("%f",b[5]);
return 0;
}
结果为0.0000
...全文
130 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
AnYidan 2013-11-20
  • 打赏
  • 举报
回复
引用 2 楼 u011922164 的回复:
果然厉害,为什么地址操作不可以,是因为分配的内存不连续吗?
p=a; //数组a 此时退化为指针 If the type of an expression or subexpression is ``array of T,'' for some type T, then the value of the expression is a pointer to the first object in the array, and the type of the expression is altered to ``pointer to T.'' This conversion does not take place if the expression is in the operand of the unary & operator, or of ++, --, sizeof, or as the left operand of an assignment operator or the . operator. Similarly, an expression of type ``function returning T,'' except when used as the operand of the & operator, is converted to ``pointer to function returning T.''
皓月鸣心 2013-11-20
  • 打赏
  • 举报
回复
果然厉害,为什么地址操作不可以,是因为分配的内存不连续吗?
max_min_ 2013-11-20
  • 打赏
  • 举报
回复

include <stdio.h>
fun(double*p)
{

double a[10]={0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0};
//p=a; //这里只是地址操作而已
memcpy((void*)p, (void*)a, sizeof(double) * 10); //用这个试试
return 0;
}

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧