函数按值和引用调用 [英] function call by value and by reference

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

问题描述

我真的很难分辨

两个..........我的意思是......任何人都知道每个人是如何发生的?

i am really having a hard time trying to differentiate the
two..........i mean.....anyone got a better idea how each occurs?

推荐答案

mi ** *******@gmail.com 写道:
我真的很难分辨
两个......... .i意味着.....任何人都知道每个人是如何发生的?
i am really having a hard time trying to differentiate the
two..........i mean.....anyone got a better idea how each occurs?




在C中,函数调用是一个函数调用。

值或参考没有调用。


如果你的意思是按价值和参考传递参数,

你也没有运气,因为C通过值传递它们/只有/。

这意味着参数的副本被传递给被调用的

函数,而不是在调用

函数中对原文的引用。


现在,这些教科书在这里也会有所帮助,你知道。 />

干杯


弗拉基米尔

-

我的电子邮件地址是真实的,我读了它。



In C, function call is a function call. There''s no calling by
value or reference.

If you meant passing parameters by value and by reference,
you''re out of luck as well, as C passes them by value /only/.
That means that a copy of the parameter is passed to the called
function, not some reference to the original in the calling
function.

Now, those textbooks would''ve helped here, too, you know.

Cheers

Vladimir
--
My e-mail address is real, and I read it.


男孩你掌握了我的电子邮件...........但是有这个传递

参考参考.....对不起,我误以为....我的意思就像当你使用指针时... b $ b你现在得到了什么?

boy you mastered my email...........but there is this passing of
parameters by reference.....sorry i mistook.... i mean like when you
use pointers... what you got now?


mi*********@gmail.com 写道:
mi*********@gmail.com wrote:
我真的很难尝试判断两个..........我的意思是......任何人都知道每个人是如何发生的?
i am really having a hard time trying to differentiate the
two..........i mean.....anyone got a better idea how each occurs?




那里是有关编程语言的书籍,可以解释这些术语。

你应该去找&读一些。


粗略地说:调用f(X)到由f(a类型为T)定义的函数是

按引用调用(更好)本来应该是按价值传递,但我们将

让...通过)如果更新参数内部f导致

(立即)更新变量X.如果改变

,它的值是按值调整的值不会改变X的值。


C没有按引用的方式调用。 C ++(当参数是定义为具有引用类型的
时)和Pascal一样(当参数

是VAR参数时)。

所以


void example(T a){a = someTValue; }


void caller(){T a = aTValue;例子(a); ......}


...'a`的值是/ still / aTValue,而不是someTValue。

即使T是一个指针类型。


-

克里斯理解是一把三刃剑 Dollin



There are books on programming languages which explain these terms.
You should go find & read some.

Roughly: a call f(X) to a function defined by f(a ofType T) is
call-by-reference (better would have been "pass by value", but we''ll
let that ... through) if updating the argument a inside f results in
(immediately) updating the variable X. It''s call-by-value if changing
the value of a doesn''t change the value of X.

C doesn''t have call-by-reference. C++ does (when the argument is
defined to have a reference type) as does Pascal (when the argument
is a VAR parameter).

So

void example( T a ) { a = someTValue; }

void caller() { T a = aTValue; example( a ); ... }

in the ... the value of `a` is /still/ aTValue, not someTValue.
Even if T is a pointer type.

--
Chris "understanding is a three-edged sword" Dollin


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

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