作者Mayinggo (馬贏狗)
看板Examination
標題[考題] 程式語言兩題
時間Wed Jun 26 19:06:38 2013
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++不熟沒學過 不過大概知道這題在考傳值傳址呼叫
某年政大資管所考題 還請各位大大不吝指教
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.35.166.245
1F:→ VampireClub:第二題pAAA rAAA函式沒有定義 , 漏打? 06/26 20:16
2F:→ GLTY:第一題我怎麼覺得是B @@? 第二題照順序跑感覺沒啥問題 06/26 20:25
3F:→ pt7441:第一題是跑程式驗證是C 06/26 20:27
4F:→ pt7441:第二題感覺有錯 06/26 20:31
5F:推 GLTY:樓上是說解答嗎? 還是內碼? 06/26 20:33
6F:→ pt7441:感覺程式應該有誤 06/26 20:36
7F:→ GLTY:我跑程式會出現:unresolved overloaded function type這串@@ 06/26 20:38
8F:推 GLTY:我研究完畢了...答案沒錯;程式碼錯了@@... 06/26 20:46
9F:→ GLTY:每個V2的地方都少了空白分隔 COUNT改為COUT...這邊我看好久XD 06/26 20:48
抱歉 我沒看到
※ 編輯: Mayinggo 來自: 114.35.166.245 (06/26 20:49)
10F:→ GLTY:還有換行是反斜線不是斜線\n <<這樣 06/26 20:49
已改正
※ 編輯: Mayinggo 來自: 114.35.166.245 (06/26 20:50)
※ 編輯: Mayinggo 來自: 114.35.166.245 (06/26 20:52)