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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 08:00, ionmjnm3041
The managing director of a company sends a christmas greeting to all his employees through the company email. which type of network does he use? he uses an .
Answers: 3
image
Computers and Technology, 23.06.2019 14:00, shawn423
How are stop motion special effects in animated films created
Answers: 1
image
Computers and Technology, 24.06.2019 03:00, SiegeHatake4534
Will do anything for brainlest so can you guys me out i will try my best to you out
Answers: 1
image
Computers and Technology, 24.06.2019 13:30, andybiersack154
Consider jasper’s balance sheet. which shows how to calculate jasper’s net worth?
Answers: 1
You know the right answer?
Consider the following program written in C syntax:

void main () {

int value...

Questions in other subjects:

Konu
Spanish, 22.09.2019 10:20