Monday 1 August 2011

Swapping With Pointer.


Swap two pointers without using temporary variables?


#include<stdio.h>
#include<conio.h>
void main()
{
int i=10;
int j=20;
int *a,*b;
clrscr();
a =&i;
b=&j;
printf("Before:%d\t%d\n",*a,*b);
*a^=*b;
*b^=*a;
*a^=*b;
printf("After:%d\t%d\n",*a,*b);
getch();
}

No comments:

Post a Comment