• edited by
7,409 views
23 23 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
     

4 Answers

Best answer
34 34 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
2 2 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:
Position:
Show:

Related questions

54 54 votes
5 answers 5 answers
20.3k
20.3k views
Kathleen asked Sep 29, 2014
20,256 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)$
18 18 votes
2 answers 2 answers
9.3k
9.3k views
Kathleen asked Sep 29, 2014
9,318 views
A part of the system software which under all circumstances must reside in the main memory is:text editorassemblerlinkerloadernone of the above
35 35 votes
3 answers 3 answers
23.6k
23.6k views
Kathleen asked Sep 29, 2014
23,644 views
A simple two-pass assembler does the following in the first pass:It allocates space for the literals.It computes the total length of the program.It builds the symbol tabl...
34 34 votes
3 answers 3 answers
10.6k
10.6k views
Kathleen asked Sep 29, 2014
10,649 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