The program will give correct result if we are using two variable for input. The following code illustrate:-
#include<stdio.h>
int swap(int*,int*);
main()
{
int a,b;
printf("enter number1 and number2\n");
scanf("%d\n%d",&a,&b);
swap(&a,&b);
printf("%d\n%d",a,b);
}
int swap(int *px, int *py)
{
*px = *px - *py;
*py = *px + *py;
*px = *py - *px;
}
But if we use only one variable for input,then program will not give correct result.The following code will illustrate:-
#include<stdio.h>
int swap(int*,int*);
main()
{
int a;
printf("enter number\n");
scanf("%d\n%d",&a,&a);
swap(&a,&a);
printf("%d\n%d",a,a);
}
int swap(int *px, int *py)
{
*px = *px - *py;
*py = *px + *py;
*px = *py - *px;
}