Sunday 24 March 2013

int swap(int *a,int *b)


 int swap(int *a,int *b)
{
 *a=*a+*b;*b=*a-*b;*a=*a-*b;
}
main()
{
         int x=10,y=20;
    swap(&x,&y);
         printf("x= %d y = %d\n",x,y);
}
Answer
    x = 20 y = 10
Explanation
This is one way of swapping two values. Simple checking will help understand this.

Blog Author: Vijay Kumar

No comments:

Post a Comment