Question: I have a question which involves calling a function with 2 parameters of a pointer to a pointer

```
int main(void)
{ ...
int *ptrp = &p, *ptrq = &q;
int **ppp = &ptrp, **ppq  = &ptrq;
swap_ptr(ppp,ppq);/* &ptrp, &ptrq passed */ 
/* to swap_ptr() */
return 0;
}

void swap_ptr(int **ptrA,int **ptrB)...

```

We have to swap the values of ptrp and ptrq, so does that mean in the swap\_ptr function I just use \*ptrA and \*ptrB to swap them or is it some other pointer statement?

Thanks

Answer: 
It's the same concept as swapping anything:

```
void swap(int* a, int* b)
{
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

```

In this case, you just happen to be swapping int\* instead of int:

```
void swap(int** a, int** b)
{
    int* tmp = *a;
    *a = *b;
    *b = tmp;
}

```
Yes, `*ptrA` would refer to the variable `ptrp` in `main` and `*ptrA` would refer to `ptrq`. Swap these two values as you would for any other type and `ptrp` will now point to `q` and `ptrq` to `p`.

Since this sounds like it might be homework I'll let you come up with the three lines of code.