I have seen many articles discussing pointer swapping, in many of them, they use this code:
void ptr_swap(int **p1, int **p2)
{
int *temp = *p1;
*p1 = *p2;
*p2 = temp;
}
but I am not clear as to why it is necessary to declare temp as a pointer rather than as a natural integer. When I tested it, it did not make any difference.
void ptr_swap(int **p1, int **p2)
{
int temp = *p1;
*p1 = *p2;
*p2 = temp;
}
Thanks!