Call by value , address , reference

若只傳遞一般資料就用 call by value 避免去修改到主程式的資料

但若是要傳遞物件、陣列.....etc 這種大型資料的話 建議使用 call by

address 或是 Call by reference 來避免function 複製大型資料 浪費

記憶體空間跟降低效率。



Call by value
原型宣告: int arith( int , int , int )
函數呼叫: arith( first_term , n_term , step)
函數宣告: int arith( int under_value , int up_value , int step)
是否更改實際參數: no


Call by address
原型宣告: int arith( int * , int * , int )
函數呼叫: arith( &first_term , &n_term , step)
函數宣告: int arith( int *under_value , int *up_value , int step)
是否更改實際參數: Yes


Call by reference
原型宣告: int arith( int & , int & , int )
函數呼叫: arith( first_term , n_term , step)
函數宣告: int arith( int &under_value , int &up_value , int step)
是否更改實際參數: Yes

留言