How do I modify a pointer that has been passed into a function in C?

前端 未结 5 1618
予麋鹿
予麋鹿 2020-11-21 05:25

So, I have some code, kind of like the following, to add a struct to a list of structs:

void barPush(BarList * list,Bar * bar)
{
    // if there is no move t         


        
5条回答
  •  轮回少年
    2020-11-21 06:06

    This is a classic problem. Either return the allocated node or use a pointer of pointer. In C, you should pass a pointer to a X to a function where you want your X to be modified. In this case, since you want a pointer to be modified, you ought to pass a pointer to a pointer.

提交回复
热议问题