Ask Question

X=10;

y = 15;

mystery (x, y);

void Mystery (int one, int two)

{

int temp;

temp = one;

one = one;

two = temp;

}

3 What are the values ofx and y after thestatements above execute? (Assume that variables are properlydeclared.)

a.

x = 10; y = 10

c.

x = 15; y = 10

b.

x = 10; y = 15

d.

x = 15; y = 15

+5
Answers (1)
  1. 19 May, 20:26
    0
    The answer is x=10; y=15;

    There is no change in the values of the variables x and y.

    Explanation:

    The integer variables x and y are initialized to 10 and 15 respectively as given.

    x=10;

    y=15;

    The values of variables x and y are passed as parameters to another method, as shown.

    mystery (x, y);

    The mystery method given in the question is used to assign the same value to both the variables. The value of both the variables hold the value of x, i. e., both the variables hold the value of 10.

    void Mystery (int one, int two)

    {

    / / temporary

    int temp;

    / / temp initialized to value of variable one which contains the value of variable x

    / / temp = x or temp = 10

    temp = one;

    / / one is initialized to the value of itself or value of x

    / / one = x or one = 10

    one = one;

    / / temp is assigned value of variable x through variable one

    / / temp = 10

    / / y is also assigned value of temp variable

    / / y = 10

    two = temp;

    }

    As shown in the above steps, the mystery method is used to assign same values to variables one and two.

    The values of original variables x and y are not affected since x and y are not utilized or called inside the mystery method.

    This type of passing of parameters to a method can be described as passing a copy of the values of the parameters to the method.

    Value of variable x is passed into variable one while value of variable y is passed into variable two.

    Hence, values of variables one and two can be changed and modified without affecting the values of original variables x and y.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “X=10; y = 15; mystery (x, y); void Mystery (int one, int two) { int temp; temp = one; one = one; two = temp; } 3 What are the values ofx ...” 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