How to swap two variable without using the third variable in cpp-
this question How to Swap two variables without using a third Variable is asked much time in a face-to-face interviews or some coding round too. So it's an important question for beginners. Though it is an easy question, such types of questions improve your thinking ability.
Recommended try this question before jumping to a solution.
while swapping two integer without using third variable you need a little maths logic.
step 1- add both of integer and Assign them into a.
step 2- now subract a from b from a and assign it into b.
step 3- and now subtract b from a and assign it into a
this is how you can swap two variable without using third variable.
Code mentioned below-