Hey there, I have a few questions for my homework that I greatly appreciate. Tha
ID: 3760558 • Letter: H
Question
Hey there, I have a few questions for my homework that I greatly appreciate. Thanks!!!
Question: Parameter passing mechanisms.
Consider the following C-like program:
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 four parameter passing methods, what are all of the values of the variables value and list after each of the three calls to swap?
(a) Pass by reference.
(b) Pass by value.
(c) Pass by value-result (i.e., copy in/copy out).
(d) Pass by name.
Explanation / Answer
value = 2
list[5] = (1, 3, 5, 7, 9);
NOTHING CAHNGES BECAUSE IT IS CALLED BY PASS BY VALUE
(b) Pass by value.