0

What's meant by swapping really ??

22nd Nov 2016, 10:42 AM
N.Guy
N.Guy - avatar
2 Antworten
+ 2
In simple words swapping is nothing but exchanging the values stored in two variables. Consider x = 7 and y = 3 . And in the code if you exchange the value of x with y and y with x to get x =3 and y = 7 , you have sone swapping!
22nd Nov 2016, 4:25 PM
Sampreet Gaonkar
+ 1
U have at least two value, u wanna change the value. for example: it is given: int x = 1; int y = 5; and you want int x= 5; int y =1; it is swap, change the value; in order to chane , u need temporarily variable, like temp. int temp = x; // here store x x = y; // you can store in x the value of y y = temp // because temp has the value of x
22nd Nov 2016, 10:50 AM
Ozan Karataş
Ozan Karataş - avatar