[考題] 程式語言兩題

看板Examination作者 (馬贏狗)時間11年前 (2013/06/26 19:06), 編輯推噓2(208)
留言10則, 3人參與, 最新討論串1/2 (看更多)
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

06/26 20:16, , 1F
第二題pAAA rAAA函式沒有定義 , 漏打?
06/26 20:16, 1F

06/26 20:25, , 2F
第一題我怎麼覺得是B @@? 第二題照順序跑感覺沒啥問題
06/26 20:25, 2F

06/26 20:27, , 3F
第一題是跑程式驗證是C
06/26 20:27, 3F

06/26 20:31, , 4F
第二題感覺有錯
06/26 20:31, 4F

06/26 20:33, , 5F
樓上是說解答嗎? 還是內碼?
06/26 20:33, 5F

06/26 20:36, , 6F
感覺程式應該有誤
06/26 20:36, 6F

06/26 20:38, , 7F
我跑程式會出現:unresolved overloaded function type這串@@
06/26 20:38, 7F

06/26 20:46, , 8F
我研究完畢了...答案沒錯;程式碼錯了@@...
06/26 20:46, 8F

06/26 20:48, , 9F
每個V2的地方都少了空白分隔 COUNT改為COUT...這邊我看好久XD
06/26 20:48, 9F
抱歉 我沒看到 ※ 編輯: Mayinggo 來自: 114.35.166.245 (06/26 20:49)

06/26 20:49, , 10F
還有換行是反斜線不是斜線\n <<這樣
06/26 20:49, 10F
已改正 ※ 編輯: Mayinggo 來自: 114.35.166.245 (06/26 20:50) ※ 編輯: Mayinggo 來自: 114.35.166.245 (06/26 20:52)
文章代碼(AID): #1Hoij19R (Examination)
文章代碼(AID): #1Hoij19R (Examination)