相关疑难解决方法(0)

如何修改已传递到C函数中的指针?

所以,我有一些代码,类似于以下,将结构添加到结构列表:

void barPush(BarList * list,Bar * bar)
{
    // if there is no move to add, then we are done
    if (bar == NULL) return;//EMPTY_LIST;

    // allocate space for the new node
    BarList * newNode = malloc(sizeof(BarList));

    // assign the right values
    newNode->val = bar;
    newNode->nextBar = list;

    // and set list to be equal to the new head of the list
    list = newNode; // This line works, but list only changes inside of this function
}
Run Code Online (Sandbox Code Playgroud)

这些结构定义如下:

typedef …
Run Code Online (Sandbox Code Playgroud)

c pointers pass-by-value

49
推荐指数
4
解决办法
5万
查看次数

标签 统计

c ×1

pass-by-value ×1

pointers ×1