programming-examples/c/Basic/C Program to Swap the Contents of two Numbers using Bitwise XOR Operation.c

18 lines
451 B
C
Raw Normal View History

2019-11-18 14:44:36 +01:00
/*
* C program to swap the contents of two numbers using bitwise XOR
* operation. Don't use either the temporary variable or arithmetic
* operators
*/
#include <stdio.h>
void main()
{
long i, k;
printf("Enter two integers \n");
scanf("%ld %ld", &i, &k);
printf("\n Before swapping i= %ld and k = %ld", i, k);
i = i ^ k;
k = i ^ k;
i = i ^ k;
printf("\n After swapping i= %ld and k = %ld", i, k);
}