Ask Question
23 January, 22:54

Don wishes to swap the values of the variables x and y in his program. He adds a line of code which sets the value of x to the value of y and then a line of code which sets the value of y to the value of x. What is the effect of Don's code? a. The values of both x and y will be set to the average of the original values of x and y. b. The values of both x and y will be set to the original value of x. c. The values of both x and y will be set to the original value of y. d. The values of the variables x and y will be swapped as intended.

+3
Answers (1)
  1. 23 January, 23:02
    0
    The correct answer is (c) : The value of both x and y will be set to the original value of y.

    Explanation:

    Let suppose, we assign some value to variable x and to variable y i. e.

    var x=10

    vary y=15

    Then Don adds a line of code which set the value of x to value of y i. e.

    x=y

    here it is mean that value of x become 15.

    So after this line the value of x is 15 and y is also 15

    Then he also added a line of code which set the value of y to value of x. i. e.

    y=x

    By adding this line of code, the value of y is 15 because x is equal to 15.

    Therefore, the value of both x and y will be set to the original value of y.

    Why other option are not correct

    a. After swapping the value of both variable it is impossible that both variable retain original value in it.

    b. this option is only true if in this first line he set the value of y to value of x and in the second line set the value of x to value of y.

    d. When you swap two values, there is need of third variable for swapping, when you will swap the value only between two variable, only one variable value will be retained and intended swapping will not be performed
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Don wishes to swap the values of the variables x and y in his program. He adds a line of code which sets the value of x to the value of y ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers