C:变化指针按值传递 [英] C: change pointer passed by value

查看:104
本文介绍了C:变化指针按值传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我给一个函数foo(结构节点* n),其中n是一个链表头节点。
现在,富应该n更改S.T。它指向该列表的末尾。

I have given a function foo(struct node *n) where n is the head node in a linked list. Now foo should change n s.t. it points to the end of the list.

不过,这可能与此函数签名?

But is this possible with this function signature?

假设t被指针列表的末尾

Assuming t is the pointer to the end of the list:

和n = t不会工作,因为指针是按值传递
* N = * T不会工作,我东阳将覆盖列表的头部。

n = t wont work because the pointer is passed by value *n = *t wont work, beacause I would overwrite the head of the list.

我错过了什么?

推荐答案

没有,因为你有在被传递的指针的值的副本,你必须被传递的原始指针的访问权限。为了修改指针函数外部SIG将需要美孚(结构节点** N)。

No, because you have a copy of the value of the pointer that's been passed in. You have no access to the original pointer that was passed in. In order to modify the pointer outside the function the sig would need to be foo( struct node **n).

这篇关于C:变化指针按值传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆