简单C语言函数问题

zhishiheng 2013-09-12 06:32:03
void Insert(int *&a)
{
//函数内部的参数如何解释
//&是取地址 int * 是定义一个指针变量 我理解的
//求大神科普
}
...全文
324 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
P_mor 2013-09-15
  • 打赏
  • 举报
回复
C里想修改指针的值,直接用指针的指针就行了啊,(LNode **C),没用过引用,在C里面
halleyzhang3 2013-09-14
  • 打赏
  • 举报
回复
这里'&'不是取地址,是引用
sunnydhy 2013-09-14
  • 打赏
  • 举报
回复
这明显是C++的引用啊
yangyijk 2013-09-14
  • 打赏
  • 举报
回复
要int *(&a)
patrick_zhou 2013-09-13
  • 打赏
  • 举报
回复
引用 9 楼 zhishiheng 的回复:
[quote=引用 5 楼 u012006886 的回复:] C里面你编译能通过吗
我也不是很清楚是不是C,但是这样可以用 不是很理解
//头插法建立链表 
void InsertT(LNode *&C,int arry[],int x)
{
    LNode *s,*r;
    C=(LNode*)malloc(sizeof(LNode));
    C->next=NULL;
    r=C;
    for(int i=0;i<x;++i)
    {
        s=(LNode*)malloc(sizeof(LNode));
        s->num=arry[i];
        s->next=r->next;
        r->next=s;
    }
}
[/quote] 我的理解: void InsertT(LNode *&C,int arry[],int x) 中的第一个参数是一个LNode*类型的引用,即一个对指针类型的引用,这是一个pass by reference的方式,目的是改写指针LNode* C的值(函数体内通过将malloc的值赋给C,的确达到了这个目的) 类似于这个:

void test_ref(int *&a)
{
    a = new int;
    *a = 10;
}

void main()
{
   int *p;
   test_ref(p);
   cout<<*p<<endl;
}
zhishiheng 2013-09-13
  • 打赏
  • 举报
回复
引用 5 楼 u012006886 的回复:
C里面你编译能通过吗
我也不是很清楚是不是C,但是这样可以用 不是很理解
//头插法建立链表 
void InsertT(LNode *&C,int arry[],int x)
{
    LNode *s,*r;
    C=(LNode*)malloc(sizeof(LNode));
    C->next=NULL;
    r=C;
    for(int i=0;i<x;++i)
    {
        s=(LNode*)malloc(sizeof(LNode));
        s->num=arry[i];
        s->next=r->next;
        r->next=s;
    }
}
zhishiheng 2013-09-13
  • 打赏
  • 举报
回复
引用 1 楼 turingo 的回复:
C语言有这样的语法吗?
我也不是很清楚是不是C,但是这样可以用 不是很理解
//头插法建立链表 
void InsertT(LNode *&C,int arry[],int x)
{
	LNode *s,*r;
	C=(LNode*)malloc(sizeof(LNode));
	C->next=NULL;
	r=C;
	for(int i=0;i<x;++i)
	{
		s=(LNode*)malloc(sizeof(LNode));
		s->num=arry[i];
		s->next=r->next;
		r->next=s;
	}
}
水平不流 2013-09-13
  • 打赏
  • 举报
回复
没用过这种东西.
看起来像是C++的引用.
cui0029 2013-09-13
  • 打赏
  • 举报
回复
C里面不能这样的!编译通不过的!
独孤的根号3 2013-09-13
  • 打赏
  • 举报
回复
C里面你编译能通过吗
AnYidan 2013-09-12
  • 打赏
  • 举报
回复
调用可能,定义不行
max_min_ 2013-09-12
  • 打赏
  • 举报
回复
C语言中没有引用的!
zhao 2013-09-12
  • 打赏
  • 举报
回复
C里面应该是编译不过的吧,C++是可以。
图灵狗 2013-09-12
  • 打赏
  • 举报
回复
C语言有这样的语法吗?

69,336

社区成员

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

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