Call by value,Call by ref是什麼
什麼是Call by value 和 Call by reference??他們分別的內容??差異性??
- 昱仁Lv 51 decade agoFavorite Answer
有三種喔,分別是 call by value, call by address, call by reference.
那其中call by address和call by reference是比較像的, 但是還是有些許不同.
1. Call by value
2. call by address
3.call by refence
所以跟call by address一樣,
call by value 和 call by reference 很好分辨,
就是會不會改到原本記憶體的變數內容囉!!!Source(s): 知識+(龍大) & 經驗
- prisoner26535Lv 71 decade ago
Wait, there are many more other parameter passing strategies:
by macro expansion
For ordinary programmers, you probably can live with the understanding of
call by value, by address, by reference, and by name.
But for computer scientists, you need to know each and everyone of them, and of course, why they are used by some programming languages but not the others. To do this, I think you need to know one thing first - "Side Effect".
When you design and subroutine, in addition to the functions the subroutine need to perform, you also need to determine how the subroutine should communicate with the caller. In mathematical normal form, the direction of information flows and the mechanism is very well defined, and more importantly, well understood; however, in computer programming, we may not need to be so strict. Thus, so many mechanisms are proposed to allow flexibility. So,
Call by Value - advocated by C, is to restrict the information flow to one direction only (from caller to callee), however, due to the availability of pointer type, the side effect allows the information flows in the other direction (from callee to caller.)
Call by reference - reference is same as address (pointer) without the need for explicit de-reference. FORTRAN has it for years but C disallow it. However, C++ and C# bring it back for certain reason.
2009-11-29 07:02:03 補充：
However, many papers still considered it dangerous, not for technical reason, but personal reasons - for few OO programmers read class declarations carefully enough to appreciate why a formal argument is declared to be a reference type.
2009-11-29 07:02:28 補充：
The example my ninth grade programming teacher liked to use:
cin and cout are soooooo commonly used by almost all OO programmers. But few care to read iostream classes to answer the following question:
cin >> a
evaluate to? and why it is designed that way.
2009-11-29 07:04:34 補充：
Too much already - need to stop now. Anyway, if you know how to answer the above questions, you probably can say with confidence that you know "reference" pretty well.