4 Which of the following code segments correctly swaps the v
4. Which of the following code segments correctly swaps the values of variables named x and y?
a.
x=y
y=temp
x=temp
b.
temp=x
x=y
y=temp
c.
x=y
temp=x
y=temp
d.
temp=x
y=x
x=temp
Solution
ANSWER IS OPTION B
AS
temp=x ; TEMP WILL TAKE VALUE OF X HERE
x=y ; X WILL TAKE WALUE OF Y HERE
y=temp; FINALLY Y WILL TAKE VALUE OF TEMP WHICH WAS VALUE OF X
HENCE SWAPPING IS DONE
