subject
Computers and Technology, 23.03.2020 20:41 kbuhvu

Consider the following program written in C syntax:

void main () {

int value = 2, list[5] = {1, 3, 5, 7, 9};

swap (value, list[0]);

swap (list[0], list[1]);

swap (value, list[value]);

}

void swap (int a, int b) {

int temp;

temp = a;

a = b;

b = temp;

}

For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three calls to swap?

a. Passed by value

With pass by value, none of the actual arguments are changed, so the variables retain the values they were initialized with.

b. Passed by reference

With pass by reference, the arguments are changed. After the first call to swap, value == 1 and list[0] == 2. After the second call to swap, list[0] == 3 and list[1] == 2. After the third call, value == 2 and list[1] == 1.

c. Passed by name

With pass by name, it’s as if the text of the arguments is inserted in the text of the subprogram. For the first two calls to swap, behavior is just like pass by reference. For the third call, swap acts as if it has the body

temp = value;

value = list[value];

list[value] = temp;

and as a result, value == 2 (what was stored in list[1]) and list[2] == 1. List[1] remains 2.

d. Passed by value-result

In this case, value-result has the same effect as reference.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 09:00
Which best describes the condition under which the unicode output is the same as plain text?
Answers: 3
question
Computers and Technology, 22.06.2019 18:30
Technician a says that a shop towel should never be used to clean around the flange area before replacing an automatic transmission filter. technician b says that a dimpled transmission fluid pan can be repaired. who is right
Answers: 3
question
Computers and Technology, 23.06.2019 14:00
Select the correct answer. a company is currently focusing on creating specific management goals for itself. which level of maturity is the company demonstrating under the sse_ccm framework? a. performed informally b. planned and tracked c. quantitatively controlled d. well-defined e. continuously improving
Answers: 2
question
Computers and Technology, 23.06.2019 20:30
1. for which of the following are you not required to signal beforehand? a. changing lanes b. speeding up c. stopping
Answers: 2
You know the right answer?
Consider the following program written in C syntax:

void main () {

int value...
Questions
question
World Languages, 13.04.2021 06:20
question
Mathematics, 13.04.2021 06:20
question
Chemistry, 13.04.2021 06:20
question
History, 13.04.2021 06:20
question
History, 13.04.2021 06:20