Friday, September 9, 2011

Coding Puzzle No. 7?

#include<stdio.h>

void main()
{
         int a=5,b=2;
         a^=b^=a^=b;
         printf("%d  %d",a,b);
}



Output:
2 5

ConCept:
This is a simple integer swapping program using XOR. If we expand the step, it will result into --
a = a^b;
b = a^b;
a = a^b;

No comments:

Post a Comment