How To Swap 2 Values In C
Subscribe Our Channel: / @techprogramhacks1814
Watch Video: • How To Swap 2 Values In C
==================================================
Swapping the value of two variables normally takes three lines and a temporary variable.
There are two types of conditions for such a task. Classical condition: change two numbers. The more difficult task: to change the two any types (string, float, object, other…).
The goal is to swap the values of a and b (all types).
let a = 1,
b = 2,
c = 0;
c = a;
a = b;
b = c;
Of course, we’ve introduced another variable called c to temporarily store the original value of a during the swap. But can we do it without c? Yes, we can!
Just do it! =)
Let’s start with the first task: to change the two integers.
a = a + b
b = a - b
a = a - b
==================================================
Follow Social Media :
Google+ : https://plus.google.com/u/0/115487337...