Ask Question
18 June, 15:17

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

+2
Answers (1)
  1. 18 June, 19:12
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers