I run this code and the program give me this result. But i don't know how the program can have this result. Please explain for me.
Code:
#include <stdio.h>
void swap1(int *i1,int *i2) {
int tmp;
tmp=*i1;
*i1=*i2;
*i2=tmp;
}
void swap2(int i1,int i2) {
int tmp;
tmp=i1;
i1=i2;
i2=tmp;
}
main(){
int i1,i2;
i1=100;
i2=200;
printf("i1=%d i2=%d\n",i1,i2);
swap1(&i1,&i2);
printf("i1=%d i2=%d\n",i1,i2);
swap2(i1,i2);
printf("i1=%d i2=%d\n",i1,i2);
}
The result is:
i1=100 i2=200
i1=200 i2=100
i1=200 i2=100
When i run swap1 i think that i1=200 and i2=100. So when i run swap2 they must be i1=100 and i2=200???