Pass-by-value Pass-by-reference Pass-by-value-result Pass-by-name

2014-11-24 01:01:25 · 作者: · 浏览: 10

Consider the following program written in C-like syntax (but not exactly C language):
void swap(int a, int b) {
int temp;
temp = a;
a = b;
b = temp;
}
void main( ) {
int value = 1, list[5] = {1, 3, 5, 7, 9}; /* list[0] = 1, list[1] = 3, … */
swap(value, list[value]); /* here */

}
For each of the following parameter-passing methods, what are all of the values of the
variables value and list after the call to ‘swap’ (at the point marked ‘here’) Justify
your answer.
(example answer: value = 1, list = {1, 3, 5, 7, 9}).
(a) Pass-by-value
(b) Pass-by-reference
(c) Pass-by-value-result (Assume address binding at entry)
(d) Pass-by-name