Swap values of two variables in C using XOR

Swapping of Two Numbers in C without using XOR: 

First, see the: Swapping of  two numbers in C

Swapping of Two number program in C using XOR:
#include<stdio.h>
int main()
{
 int a;
 int b;
 printf("Type value of A = ");
 scanf("%d",&a);
 printf("\nType value of B = ");
 scanf("%d",&b);
  a ^= b;
  b ^= a;
  a ^= b;

 printf("A = %d",a);
 printf("\nB : %d",b);
 return 0;
}
Output:
Type value of A = 7
Type value of B = 5
A = 5
B = 7
Explanation:
  • Two integers a, b is declared of Type int.
  • The values of a, b are taken from the keyboard given by the user.
  • Now both the values of "a" and "b" are changed using Xor.
  • And last Printf Prints the value of “a” and “b”.
See also:
Share:

Our Services

Search This Blog

  • ()
Powered by Blogger.

Alphabet Pattern (or) Character Pattern21 Program in C

Write "C"  Program to print below Alphabet Pattern21 (or) Character Pattern21: To underst...

Blog Archive