1.
Three of the following expressions have the same value. Which of the followi
ng's value is different from the others?
(A)*&Ptr
(B)&*Ptr
(C)*Ptr
(D)Ptr
某年中正資管所考題 去看yahoo知識+有人說答案是(C) 書上答案是寫(D)
記得是取值和取址 可是說只有一個跟其他不同......
2.
Show what is written by the following C++ code.
#include <iostream>
using namespace std;
void AAA(int v1,int v2)
{int tmp=v2;v2=v1-3;v1=tmp+3;}
void pAAA(int *v1,int *v2)
{int tmp=*v2;*v2=*v1+2;*v1=tmp-4;}
void rAAA(int &v1,int &v2)
{int tmp=v2;*v2=v1+4;v1=tmp-5;}
int main()
{int i=1;
int j=2;
cout<<"before AAA() i="<<i<<" and j="<<j<<"\n";
AAA(i,j);
cout<<"after AAA() i="<<i<<"and j="<<j<<"\n";
pAAA(&i,&j);
cout<<"after pAAA() i="<<i<<" and j="<<j<<"\n";
rAAA(i,j);
cout<<"after rAAA() i="<<i<<" and j="<<j<<"\n";
return 0;
}
解答是before AAA() i=1 and j=2
after AAA() i=1 and j=2
after pAAA() i=-2 and j=3
after rAAA() i=-2 and j=2
C++不熟沒學過 不過大概知道這題在考傳值傳址呼叫
某年政大資管所考題 還請各位大大不吝指教
--
Three of the following expressions have the same value. Which of the followi
ng's value is different from the others?
(A)*&Ptr
(B)&*Ptr
(C)*Ptr
(D)Ptr
某年中正資管所考題 去看yahoo知識+有人說答案是(C) 書上答案是寫(D)
記得是取值和取址 可是說只有一個跟其他不同......
2.
Show what is written by the following C++ code.
#include <iostream>
using namespace std;
void AAA(int v1,int v2)
{int tmp=v2;v2=v1-3;v1=tmp+3;}
void pAAA(int *v1,int *v2)
{int tmp=*v2;*v2=*v1+2;*v1=tmp-4;}
void rAAA(int &v1,int &v2)
{int tmp=v2;*v2=v1+4;v1=tmp-5;}
int main()
{int i=1;
int j=2;
cout<<"before AAA() i="<<i<<" and j="<<j<<"\n";
AAA(i,j);
cout<<"after AAA() i="<<i<<"and j="<<j<<"\n";
pAAA(&i,&j);
cout<<"after pAAA() i="<<i<<" and j="<<j<<"\n";
rAAA(i,j);
cout<<"after rAAA() i="<<i<<" and j="<<j<<"\n";
return 0;
}
解答是before AAA() i=1 and j=2
after AAA() i=1 and j=2
after pAAA() i=-2 and j=3
after rAAA() i=-2 and j=2
C++不熟沒學過 不過大概知道這題在考傳值傳址呼叫
某年政大資管所考題 還請各位大大不吝指教
--
All Comments