162k views
4 votes
Swapping the contents of two variables requires a third variable that can serve as a temporary storage location. True False.

User DrYap
by
8.6k points

1 Answer

2 votes

Answer:

True.

Explanation:

True.

Let's say A = 5, and B = 10.

We need to swap the contents of A and B, so A will end up with 10 and B will end up with 5.

A = 5

B = 10

Introduce variable C.

C = A (now C contains 5)

A = B (now A contains 10)

B = C (now B contains 5)

In the last two steps above, you see that the values of A and B were swapped.

User Yamass
by
7.6k points