a- 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? 1. Passed by value 2. Passed by reference 3. Passed by resul

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.5: Case Studies
Problem 3E
icon
Related questions
Question
100%

a- 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?

1. Passed by value
2. Passed by reference
3. Passed by result

Question3: 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?
1. Passed by value
2. Passed by reference
3. Passed by result
By value
By reference
By result
Output
Transcribed Image Text:Question3: 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? 1. Passed by value 2. Passed by reference 3. Passed by result By value By reference By result Output
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr