瀏覽單個文章
m5a8258
Major Member
 
m5a8258的大頭照
 

加入日期: Apr 2001
您的住址: 藍色星球
文章: 223
關於資料結構..call by ***

請問各位大大們..請問一下資料結構問題
call by address 傳址
call by name 傳名
call by reference

怎麼運作以及舉例呢??

另外.. *x 指的是x的pointer指標
&x 指的是x的記憶體位置
降子對嗎??
感謝囉....

附上一個題目
Consider the following C/C++ programs:
Give the output of the following C++ program
#include<studio.h>
long K,L;
long P(long X){
long L; L=X+1; K=K+1
return L+(X++);
}
long Q(long& X){
long K; L=X+1; K=K+1
return L+(X++);
}
int main(){
int ans;k=1;L=1;
ans=P(K); printf("%3d%3d%3d\n",ans,K,L);
ans=P(L); printf("%3d%3d%3d\n",ans,K,L);
ans=Q(K); printf("%3d%3d%3d\n",ans,K,L);
ans=Q(L); printf("%3d%3d%3d\n",ans,K,L);
}

答案是
4 1 2
6 1 3
4 2 2
7 2 4

小弟比較不明白的是ans=Q(L)這段...的L+(X++)..因為是採用call by reference..ans
答案怎麼會是7...??
煩請解惑..thanks
     
      
__________________
My Blog
http://www.chengwei.idv.tw
舊 2005-11-19, 01:28 AM #1
回應時引用此文章
m5a8258離線中