微信

使用微信服务,更方便

职友集>程序员面试题 > Pass-by-value Pass-by-reference Pass-by-value-result Pass-by-name

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

2014-05-20 06:30:01 阅读( 79 )

1766人 收藏本页

标签:程序员面试题

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

来自IT公司面试手册

下一篇:雅迅网络的上机题

上一篇:程序员技术类面试、笔试题汇总

亲~ 如果您有更好的答案 可在评论区发表您独到的见解。

您想查看更多的信息: 面试题