C:变化指针按值传递 [英] C: change pointer passed by value
问题描述
我给一个函数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屋!