Write a program to swap two numbers without using a third variable.

AnswerBot
11mo
Swapping two numbers without using a third variable in a program.
Use bitwise XOR operation to swap two numbers without using a third variable.
Example: int a = 5, b = 10; a = a ^ b; b = a ^ b; a = a ^ ...read more
Goutham Karthi
1y
int a = 1, b = 2;
a = a + b; //a = 1 + 2 a = 3
b = a - b; //b = 3 - 2 b = 1
a = a - b; //a = 3 - 1 a = 2
printf(“After Swapping A is %d B is %d”, a,b);
Help your peers!
Add answer anonymously...
Capgemini Software Engineer interview questions & answers
A Software Engineer was asked 1w agoQ. How do you communicate between Microservices?
A Software Engineer was asked 1mo agoQ. Given a string, determine if it is a palindrome, considering only alphanumeric c...read more
A Software Engineer was asked 1mo agoQ. What is the difference between local and global variables?
Popular interview questions of Software Engineer
A Software Engineer was asked 1mo agoQ1. Given a string, determine if it is a palindrome, considering only alphanumeric c...read more
A Software Engineer was asked 1mo agoQ2. Briefly describe the C language.
A Software Engineer was asked 1mo agoQ3. What is the difference between local and global variables?
Top HR questions asked in Capgemini Software Engineer
A Software Engineer was asked 7mo agoQ1. What was your role in your previous project?
A Software Engineer was asked 8mo agoQ2. What are you good at?
A Software Engineer was asked 8mo agoQ3. Where do you see yourself in five years?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

