Ask Question
20 May, 12:56

A code segment will be used to swap the values of the variables a and b using the temporary variable temp. Which of the following code segments correctly swaps the values of a and b?

a) a to b, temp to a, b to temp

b) temp to a, a to b, b to temp

c) temp to a, a to temp, a to b

d) temp to a, b to temp, a to b

+3
Answers (1)
  1. 20 May, 13:08
    0
    Option (b)

    Explanation:

    These are the right statements but the correct order would be:

    temp=b;

    b=a;

    a=temp;

    Value of b will be stored in temp variables and then value of a will be stored in b and afterwards value of temp variable to a. This is how value of a &b will be swapped. Swapping is needed in various codes many times. For example - while sorting an array, while reversing a string, etc.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “A code segment will be used to swap the values of the variables a and b using the temporary variable temp. Which of the following code ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers