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

前端 未结 5 1527
予麋鹿
予麋鹿 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 05:58

    Remember, in C, EVERYTHING is passed by value.

    You pass in a pointer to a pointer, like this

    int myFunction(int** param1, int** param2) {
    
    // now I can change the ACTUAL pointer - kind of like passing a pointer by reference 
    
    }
    

提交回复
热议问题