recategorized by
4,142 views
19 votes
19 votes

What does the following code do?

var a, b: integer;
begin
    a:=a+b;
    b:=a-b;
    a:a-b;
end;
  1. exchanges $a$ and $b$
  2. doubles $a$ and stores in $b$
  3. doubles $b$ and stores in $a$
  4. leaves $a$ and $b$ unchanged
  5. none of the above
     
recategorized by

3 Answers

Best answer
27 votes
27 votes
Answer is simply $A$ i.e. it swaps the values of the two.. Take any two values for $A$ and $B$. and perform the given operations over them.
edited by
1 votes
1 votes

1. a= a+b

2. b= a-b= (a+b)-b= a (from 1)

3. a= a-b= (a+b) - (a) = b (from 1 and 2)

Hence the values are getting exchanged

Answer(A).

Answer:

Related questions

41 votes
41 votes
5 answers
1
Kathleen asked Sep 29, 2014
12,588 views
$\displaystyle \sum_{1\leq k\leq n} O(n)$, where $O(n)$ stands for order $n$ is:$O(n)$$O(n^2)$$O(n^3)$$O(3n^2)$$O(1.5n^2)$
14 votes
14 votes
2 answers
2
Kathleen asked Sep 29, 2014
6,349 views
A part of the system software which under all circumstances must reside in the main memory is:text editorassemblerlinkerloadernone of the above
27 votes
27 votes
2 answers
3
27 votes
27 votes
3 answers
4
Kathleen asked Sep 29, 2014
6,849 views
Let A be a finite set of size n. The number of elements in the power set of $A\times A$ is:$2^{2^n}$$2^{n^2}$$\left(2^n\right)^2$$\left(2^2\right)^n$None of the above