123k views
1 vote
(5 points) Extra** CHAPTER 9 Consider the following program written in C syntax: void swap(int a, int b) { int temp; temp = a; a = b; b = temp; } 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]); } 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 b. Passed by reference c. Passed by value-result

1 Answer

5 votes

Answer:

after 1st swap

value=2 ,list[0]=1

after 2nd swap

list[0]=1,list[1]=3

after 3rd swap

value=2,list[value]=5.

Passed By Value.

Step-by-step explanation:

As we see the parameters passed to the function are passed by value they are not passed by reference so there will be no swapping performed on the original values because when the arguments are passed by value the function creates a copy of original arguments and work on those duplicate arguments.Hence no change will be reflected on the original arguments.

User Gga
by
5.2k points