Swapping objects using pointers

后端 未结 10 1342
轻奢々
轻奢々 2020-12-03 18:20

I\'m trying to swap objects for a homework problem that uses void pointers to swap objects. The declaration of my function has to be:

void swap(void *a, voi         


        
10条回答
  •  遥遥无期
    2020-12-03 18:29

    Parameters are like local variables, with values copied into them before the function starts executing. This prototype:

    void swap(void *a, void *b, size_t size);
    

    Means that the two addresses are copied into new variables called a and b. So if you change what is stored in a and b, nothing you do will have an any effect after swap returns.

提交回复
热议问题