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, 21.06.2019 18:00
Which if the following allows you to view and access important information about your documents all in one location
Answers: 3
question
Computers and Technology, 22.06.2019 14:30
Hi plz 11 ! when planning a table, what step comes first: "define the column headers" or "calculate the number of columns/rows"? a. calculate the number of columns/rows b. define the column headers
Answers: 1
question
Computers and Technology, 23.06.2019 06:00
When is a chart legend used a. all the time b. whenever you are comparing data that is the same c. whenever you are comparing multiple sets of data d. only for hand-drawn charts
Answers: 2
question
Computers and Technology, 23.06.2019 11:30
In cell h5 enter a formula that will calculate the percentage of attendees that went to the altamonte springs job fair in 2018.
Answers: 1
You know the right answer?
Consider the following program written in C syntax:

void main () {

int value...
Questions
question
Mathematics, 22.08.2019 13:20
Questions on the website: 13722367