#include <stdio.h>
#include <string.h>
void swap(int *p1, int *p2)
{
int *temp;
temp=p1;
p1=p2;
p2=temp;
}
main()
{
int n1=10,n2=20;
printf("%d,%d\n",n1++,++n2);
swap(&n1,&n2);
printf("%d,%d",++n1,n2++);
}
When I run this code output is 10,21 and 12,21. My question is why values of N1 and N2 are not swapped? Since function swap uses pointers and method is called by reference shouldn't they swap? Or am I missing some concept? Thanks in advance