Question 6922 – UGC NET CS 2015 Dec – paper-3
April 14, 2024Programming
April 14, 2024Programming
|
Question 6
|
What does the following code do?
var a, b : integer;
begin
a:=a+b;
b:=a-b;
a:=a-b
end;
|
exchanges a and b
|
|
|
doubles a and stores in b
|
|
|
doubles b and stores in a
|
|
|
leaves a and b unchanged
|
|
|
none of the above
|
Question 6 Explanation:
Exchanges a and b.
Let us consider a=5; b=2
a := a+b = 5+2 = 7
b := a-b = 7-2 = 5
a := a-b = 7-5 = 2
O/P: a=2; b=5
Let us consider a=5; b=2
a := a+b = 5+2 = 7
b := a-b = 7-2 = 5
a := a-b = 7-5 = 2
O/P: a=2; b=5
Correct Answer: A
Question 6 Explanation:
Exchanges a and b.
Let us consider a=5; b=2
a := a+b = 5+2 = 7
b := a-b = 7-2 = 5
a := a-b = 7-5 = 2
O/P: a=2; b=5
Let us consider a=5; b=2
a := a+b = 5+2 = 7
b := a-b = 7-2 = 5
a := a-b = 7-5 = 2
O/P: a=2; b=5
