Q:

C Program to swap two numbers using bitwise XOR operator

0

C Program to swap two numbers using bitwise XOR operator

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
void swap(int *a, int *b); 
int main()
{
    int a,b;
     
    printf("Enter first number: ");
    scanf("%d",&a);
    printf("Enter second number: ");
    scanf("%d",&b);
     
    printf("Before swapping: a=%d, b=%d\n",a,b);
    swap(&a,&b);
    printf("After swapping:  a=%d, b=%d\n",a,b);
     
    return 0;
}
 

void swap(int *a,int *b)
{
    *a  =   *a ^ *b;
    *b  =   *a ^ *b;
    *a  =   *a ^ *b;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now