我在 c 中有这个结构
struct node{
int info;
struct node* link;
};
这个过程:
void example(struct node** head){
struct node* tmp;
tmp=*head;
tmp->info=0;
*head=tmp;
}
并在主程序中调用程序
example(&head);
所以要修改 head->info 我需要一个支持变量,还有另一种没有支持变量的方法吗?
最佳答案
使用这个:
void example(struct node** head){
(*head)->info=100;
}
它将执行与您的示例
函数相同的操作。
通过取消引用 struct node**
,我们得到了 struct node*
,然后我们可以使用 ->
箭头运算符简单地访问它的成员。
关于c - 如何使用带有双指针变量(没有支持变量)的结构字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60238835/