Bla*_*ary 0 c pass-by-reference data-structures
大编辑:
好的,我原来的问题对我没有帮助.这是第二次.
我的结构看起来像这样:
struct node {
char *name;
int age;
struct node *nextName;
struct node *nextAge;
};
Run Code Online (Sandbox Code Playgroud)
我必须用这样的结构制作两个链表.所以我有'rootAges'跟踪基于年龄的列表的开始位置,'rootNames'跟踪名称的起始位置.我似乎无法让这些更新.
也就是说,我有struct node*rootAges和struct node*rootNames.我需要将这两个传递给一个将元素添加到列表中的函数.但是,当我向列表中添加内容时,我还需要改变根源.到目前为止提供的方法,例如在main函数中,当在add函数中被改变时,没有改变rootAges的值.
谢谢!
您将结构实例的地址传递给接受C中指针的函数.
void fn(struct data *p)
{
if(p)
p->x = 33;
}
//... main ...
struct data d;
fn(&d);
//d.x == 33
Run Code Online (Sandbox Code Playgroud)