ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

Pass-by-value Pass-by-reference Pass-by-value-result Pass-by-name
2014-11-24 01:01:25 ¡¾´ó ÖРС¡¿ ä¯ÀÀ:2581´Î
Tags£ºPass-by-value Pass-by-reference Pass-by-value-result Pass-by-name

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


¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
ÉÏһƪ£ºÒ»Ì×SQL¾­µäµÄÃæÊÔÌâ¼°´ð°¸ ÏÂһƪ£º³ÌÐòÔ±¼¼ÊõÀàÃæÊÔ¡¢±ÊÊÔÌâ»ã×Ü

×îÐÂÎÄÕÂ

ÈÈÃÅÎÄÕÂ

Hot ÎÄÕÂ

Python

C ÓïÑÔ

C++»ù´¡

´óÊý¾Ý»ù´¡

linux±à³Ì»ù´¡

C/C++ÃæÊÔÌâÄ¿