about c++

2007-03-24 4:05 am
wt are pass-by-value and pass-by-reference?

回答 (1)

2007-03-24 4:59 am
✔ 最佳答案
1) pass-by-value
When a calling program passes a var to a called prog/function by value, the called one will copy its content to a local var and use it. Which means that the 2 vars are in different memory locations even though they have the same name. If the called prog/func changed the value of this var, it will not be reflected when returning to the calling program.

2) pass-by-reference
When a calling program passes a var to a called prog/func by reference, it passes a pointer with the address of this var to the called one. Which means that the var used by the called prog/func has the same memory location with the var in the calling program. If the called prog/func changed the content of this var, after returning, the calling program will have the var with the updated value.


收錄日期: 2021-04-25 15:35:41
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070323000051KK03328

檢視 Wayback Machine 備份