由价值的参考和呼叫通话的区别 [英] Difference between call by reference and call by value
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/2207179/difference-between-value-parameter-and-reference-parameter\">Difference值参数和引用参数之间?
块引用>什么是由价值的参考和呼叫通话区别?
解决方案在C,有引用没有呼叫。你可以得到的最接近正在一个地址,并通过该地址的副本。(按价值计算 - 见下文)
在C ++中,通过引用调用传递给一个对象的引用(原始对象的别名)。一般来说,这将实现为对象的地址,虽然这不能保证。
打电话值意味着采取某种形式的价值,并通过该值的副本的功能。
的基本区别是,当你按值传递参数,函数只接收原始对象的的复制的,所以它不能做任何事情影响到原始对象。与按引用传递,它得到原始对象的引用,所以它可以访问原来的对象,而不是它的一个副本 - 除非它是一个const引用,它可以修改原来的对象(一个例子)。 p>
Possible Duplicate:
Difference between value parameter and reference parameter ?What is the difference between call by reference and call by value?
解决方案In C, there is no call by reference. The closest you can get is taking an address, and passing a copy of that address (by value -- see below).
In C++, call by reference passes a reference to an object (an alias for the original object). Generally this will be implemented as the object's address, though that's not guaranteed.
Call by value means taking a value of some sort, and passing a copy of that value to the function.
The basic difference is that when you pass a parameter by value, the function receives only a copy of the original object, so it can't do anything to affect the original object. With pass by reference, it gets a reference to the original object, so it has access to the original object, not a copy of it -- unless it's a const reference, it can modify the original object (for one example).
这篇关于由价值的参考和呼叫通话的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!