How do you swap two integer values without using a third variable?

AnswerBot
2y
Swapping two integer values without using a third variable.
Use XOR operator to swap two integers without using a third variable.
Addition and subtraction can also be used to swap two integers.
Bitwise o...read more
Shanmuga Priya.S
8mo
Using arithmetic operations
a = 5
b = 10
a = a + b # a now becomes 15 (5 + 10)
b = a - b # b becomes 5 (15 - 10)
a = a - b # a becomes 10 (15 - 5)
print("a:", a, "b:", b)
akshansh Kandari
1y
python code
a=5
b=6
a=a+b
b=a-b
a=a-b
print('a is :' ,a)
print('b is :',b)
output:
a is : 6
b is : 5
Add answer anonymously...
Coforge Software Engineer interview questions & answers
A Software Engineer was asked 8mo agoQ. Write pseudo code for sorting.
A Software Engineer was asked 11mo agoQ. Write a program to reverse a string.
A Software Engineer was asked 11mo agoQ. What is your knowledge of databases?
Popular interview questions of Software Engineer
A Software Engineer was asked 8mo agoQ1. Write pseudo code for sorting.
A Software Engineer was asked 11mo agoQ2. Write a program to reverse a string.
A Software Engineer was asked 11mo agoQ3. What is your knowledge of databases?
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

