SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
Swap two numbers using Bitwise operator & without using third variable
Swap two numbers using Bitwise operator & without using third variable
Implementation:
#include
int main(void) { int a,b; printf("Enter the value of a:\n"); scanf("%d",&a); printf("Enter the value of b:\n"); scanf("%d",&b); printf("Before Swap: a=%d, b=%d\n",a,b); a=a^b; // a=5^6=3 b=a^b; // b=3^6=5 a=a^b; // a=3^5=6 printf("After Swap: a=%d, b=%d\n",a,b); return 0; }
PREVIOUS
NEXT
HOME