|
Major Member
|
請問各位大大們..請問一下資料結構問題
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
|