Swapping addresses of pointers in C++

后端 未结 5 2073
温柔的废话
温柔的废话 2021-01-01 02:38

How can one swap pointer addresses within a function with a signature?

Let\'s say:

int weight, height;
void swap(int* a, int* b);

S

5条回答
  •  渐次进展
    2021-01-01 02:59

    If you want to change address of pointers then you have to pass pointers of those pointers as your parameters:

    void swap(int **a, int **b); //as prototype
    

    Those examples are just changes values of pointers.

提交回复
热议问题