Thursday, 20 September 2012

C programming code to swap using bitwise XOR

#include <stdio.h>
 
int main()
{
  int x, y;
 
  scanf("%d%d", &x, &y);
 
  printf("x = %d\ny = %d\n", x, y);
 
  x = x ^ y;
  y = x ^ y;
  x = x ^ y;
 
  printf("x = %d\ny = %d\n", x, y);
 
  return 0;
}

No comments:

Post a Comment