如何修改传递给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}
typedef struct Bar{ // this isn't too important} Bar;#define EMPTY_LIST NULLtypedef struct BarList{ Bar * val; struct BarList * nextBar;} BarList;
BarList * l;l = EMPTY_LIST;barPush(l,&b1); // b1 and b2 are just Bar'sbarPush(l,&b2);
函数式编程
猛跑小猪
幕布斯6054654