You've swapped the pointers rather than the values. Remember that C exclusively uses pass-by-value, and so these pointers were passed by value. To swap the things that they refer to you need to de-reference the pointers.
void swap(int *p1, int *p2)
{
int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
One way to thing about this is that you need to be assigning values of type int
. But your code assigns values of type int*
. And so purely on that analysis which is based only on types, you are able to reject your code.