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
Yes,
*ptrAwould refer to the variableptrpinmainand*ptrAwould refer toptrq. Swap these two values as you would for any other type andptrpwill now point toqandptrqtop.Since this sounds like it might be homework I’ll let you come up with the three lines of code.