按价值呼叫 [英] call by value

查看:86
本文介绍了按价值呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Group,

我知道关于这个话题有很多问题,但我希望

澄清这个非常基本的概念。

in:


int main(){

int j;

j = f(8);

.....}

int f(int i){


返回i * i; <然后在计算机的深处就会发生这样的事情。


参数
}


然后在计算机的深处。 f为8的被分配给int i,一个f(int

i)唯一的变量,它是为了履行f(int i)的义务而创建的,并且

被销毁一次我退回了。 (被描述为通过

副本8到该功能)


对不起,如果这真的很简陋,但我刚刚看到了光当

数组作为参数传递时(我知道,与上面的不一样)和

想要回到基础知识片刻。


谢谢

Hi Group,
I know there have been many questions on this topic, but I wish to
clarify this very basic concept.

in:

int main(){
int j;
j = f(8);
.....}

int f(int i){

return i * i;

}

then in the depths of the computer, is this what occurs.

argument of f ie "8" is assigned to int i, a variable unique to f(int
i), which has been created to fulfill the obligations of f(int i), and
is destroyed once i * i is returned. ( which is described as passing a
copy of "8" to the function)

Sorry if this is really rudimentary, but I just saw the light when
arrays are passed as arguments ( I know, not the same as above) and
wanted to go back to the very basics for a moment.

Thanks

推荐答案

mdh说:
mdh said:

Hi Group,

我知道关于这个话题有很多问题,但我希望

澄清这个非常基本的概念。


in:


int main(){

int j;

j = f(8);

....}


int f(int i){


返回i * i;


}


然后在计算机的深处,这是发生了什么。


f的参数即8,即8。被分配给int i,一个f(int

i)唯一的变量,它是为了履行f(int i)的义务而创建的,并且

被销毁一次我退回了。 (描述为将

副本8传递给该函数)
Hi Group,
I know there have been many questions on this topic, but I wish to
clarify this very basic concept.

in:

int main(){
int j;
j = f(8);
....}

int f(int i){

return i * i;

}

then in the depths of the computer, is this what occurs.

argument of f ie "8" is assigned to int i, a variable unique to f(int
i), which has been created to fulfill the obligations of f(int i), and
is destroyed once i * i is returned. ( which is described as passing a
copy of "8" to the function)



是。更具体地说,8是***评价***。事实证明,在一个可能很长且曲折的计算之后,在这种情况下,实际上可能很短,实际上可能很短,因此得到的值为8.结果是

存储在i对象中,该对象是作为调用f函数的
过程的一部分创建的。 return语句计算返回

表达式,i * i,得到一个值,然后存储在一个适合返回值的地方

(很可能直接进入main' 'sj,

,但可能通过注册表或其他东西)。然后函数返回

,并且,作为返回过程的一部分,i对象被销毁。

Yes. To be more specific, 8 is ***evaluated***. It turns out, after a
potentially long and tortuous calculation which in this case is
actually probably quite short, to have the value 8. That result is
stored in the i object that is created as part of the process of
invoking the f function. The return statement evaluates the return
expression, i * i, resulting in a value which is then stored in a place
appropriate for return values (quite possibly directly into main''s j,
but perhaps via a register or something). Then the function returns
and, as part of the process of returning, the i object is destroyed.


对不起,如果这真的很简陋,但是我刚刚看到了这个灯,当
数组作为参数传递时(我知道,与上面不一样)和

想要回到基础知识时刻。
Sorry if this is really rudimentary, but I just saw the light when
arrays are passed as arguments ( I know, not the same as above) and
wanted to go back to the very basics for a moment.



即使是数组也与上面完全相同。实际传递的内容

不是数组,而是涉及数组的表达式。评估表达式

,评估结果存储在

参数对象中。


诀窍是意识到参数是对象,但参数是

表达式。表达式被评估,这样获得的值

存储在参数对象中。


-

Richard Heathfield< http ://www.cpax.org.uk>

电子邮件:-www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

It''s exactly the same as above, even with arrays. What you actually pass
is not an array, but an expression involving an array. That expression
is evaluated, and the result of the evaluation is stored in the
parameter object.

The trick is to realise that parameters are objects, but arguments are
expressions. Expressions are evaluated, and the values thus obtained
are stored in parameter objects.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


7月28日凌晨3:51,Richard Heathfield:
On Jul 28, 3:51 am, Richard Heathfield :

mdh说:
mdh said:


int main(){

int j;

j = f(8);

....}
int main(){
int j;
j = f(8);
....}


int f(int i){
int f(int i){


return i * i;
return i * i;


}
}



是。更具体地说,8是***评估*** ....... snip ......

Yes. To be more specific, 8 is ***evaluated***.......snip......


>

即使是数组也与上面完全一样。实际传递的内容

不是数组,而是涉及数组的表达式。评估表达式

,评估结果存储在

参数对象中。


诀窍是意识到参数是对象,但参数是

表达式。表达式被评估,这样获得的值

存储在参数对象中。
>
It''s exactly the same as above, even with arrays. What you actually pass
is not an array, but an expression involving an array. That expression
is evaluated, and the result of the evaluation is stored in the
parameter object.

The trick is to realise that parameters are objects, but arguments are
expressions. Expressions are evaluated, and the values thus obtained
are stored in parameter objects.



我喜欢它。

因此,在数组作为参数的情况下,例如,它将被评估,并且结果(第一个元素的地址)在Object参数(类型指向Array类型的指针)中存储了

,如果我

正确理解你。


I like that.
So, in the case of the "array as argument" example, it would be
evaluated, and the result ( the address of the first element) stored
in the Object parameter (of type pointer to Array-type), if I
understand you correctly.


mdh说:
mdh said:

7月28日凌晨3:51,Richard Heathfield:
On Jul 28, 3:51 am, Richard Heathfield :



< snip>

<snip>


>诀窍是要意识到参数是对象,但参数
是表达式。评估表达式,并且因此获得的值存储在参数对象中。
>The trick is to realise that parameters are objects, but arguments
are expressions. Expressions are evaluated, and the values thus
obtained are stored in parameter objects.



我喜欢。

因此,在数组作为参数的情况下例如,它将被评估,并且结果(第一个元素的地址)在Object参数(类型指向Array类型的指针)中存储了

,如果我

正确理解你。


I like that.
So, in the case of the "array as argument" example, it would be
evaluated, and the result ( the address of the first element) stored
in the Object parameter (of type pointer to Array-type), if I
understand you correctly.



正是如此,是的。


-

Richard Heathfield< http:/ /www.cpax.org.uk>

电子邮件:-www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

Precisely so, yes.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这篇关于按价值呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆