I tried to swap two integer using pointers...
#include<stdio.h>
int main()
{
int a,b,*i,*j;
printf("Enter two integer:");
scanf("%d%d",&a,&b);
i=&a;
j=&b;
a=*j;
b=*i;
printf("\n %d \t %d",a,b);
return 0;
}
The input is
12 45
The output is
45 45
After some trials, I found that If I assigned the b=*i first and then assigned a=*j, the first integer i.e 12 is repeating..
Why this happens ?
In my understanding of pointer, this is what I've done.
I've assigned the *j (i.e value of variable stored in address of a) to b and *i(i.e value of variable stored in address of b) to a..
Please explains what really happens in this program..