程式語言兩題 - 考試

Table of Contents

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++不熟沒學過 不過大概知道這題在考傳值傳址呼叫

某年政大資管所考題 還請各位大大不吝指教

--

All Comments

Donna avatarDonna2013-06-29
第二題pAAA rAAA函式沒有定義 , 漏打?
James avatarJames2013-06-29
第一題我怎麼覺得是B @@? 第二題照順序跑感覺沒啥問題
Frederica avatarFrederica2013-06-29
第一題是跑程式驗證是C
Valerie avatarValerie2013-07-01
第二題感覺有錯
Liam avatarLiam2013-07-02
樓上是說解答嗎? 還是內碼?
Charlotte avatarCharlotte2013-07-04
感覺程式應該有誤
Dorothy avatarDorothy2013-07-06
我跑程式會出現:unresolved overloaded function type這串@@
Callum avatarCallum2013-07-10
我研究完畢了...答案沒錯;程式碼錯了@@...
John avatarJohn2013-07-14
每個V2的地方都少了空白分隔 COUNT改為COUT...這邊我看好久XD
James avatarJames2013-07-16
還有換行是反斜線不是斜線\n <<這樣