Computers and Technology
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.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 16:00, babyshazi
In a cellular network each cell is controlled by a tower what are these towers called?
Answers: 3
image
Computers and Technology, 21.06.2019 18:30, sumayyahjj
An attribute on a webpage allows you to set borders and change background colors. true or false
Answers: 1
image
Computers and Technology, 23.06.2019 11:00, shawn20034
This chapter lists many ways in which becoming computer literate is beneficial. think about what your life will be like once you’re started in your career. what areas of computing will be most important for you to understand? how would an understanding of computer hardware and software you in working from home, working with groups in other countries and contributing your talents.
Answers: 1
image
Computers and Technology, 23.06.2019 18:00, yedida
File account. java (see previous exercise) contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and account number, and return a string representation. note that the constructor for this class creates a random account number. save this class to your directory and study it to see how it works. then write the following additional code: 1. suppose the bank wants to keep track of how many accounts exist. a. declare a private static integer variable numaccounts to hold this value. like all instance and static variables, it will be initialized (to 0, since it’s an int) automatically. b. add code to the constructor to increment this variable every time an account is created. c. add a static method getnumaccounts that returns the total number of accounts. think about why this method should be static - its information is not related to any particular account. d. file testaccounts1.java contains a simple program that creates the specified number of bank accounts then uses the getnumaccounts method to find how many accounts were created. save it to your directory, then use it to test your modified account class.
Answers: 3
Do you know the correct answer?
Consider the following program written in C syntax:

void main () {

int value...

Questions in other subjects: