程式語言兩題 - 考試
By Cara
at 2013-06-26T19:06
at 2013-06-26T19:06
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++不熟沒學過 不過大概知道這題在考傳值傳址呼叫
某年政大資管所考題 還請各位大大不吝指教
--
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++不熟沒學過 不過大概知道這題在考傳值傳址呼叫
某年政大資管所考題 還請各位大大不吝指教
--
Tags:
考試
All Comments
By Donna
at 2013-06-29T04:11
at 2013-06-29T04:11
By James
at 2013-06-29T05:13
at 2013-06-29T05:13
By Frederica
at 2013-06-29T21:30
at 2013-06-29T21:30
By Valerie
at 2013-07-01T09:25
at 2013-07-01T09:25
By Liam
at 2013-07-02T09:48
at 2013-07-02T09:48
By Charlotte
at 2013-07-04T09:10
at 2013-07-04T09:10
By Dorothy
at 2013-07-06T04:47
at 2013-07-06T04:47
By Callum
at 2013-07-10T17:26
at 2013-07-10T17:26
By John
at 2013-07-14T18:05
at 2013-07-14T18:05
By James
at 2013-07-16T16:40
at 2013-07-16T16:40
Related Posts
102年台電綜合行政 專B第1,8,16題
By Steve
at 2013-06-26T18:13
at 2013-06-26T18:13
考前該如何衝刺
By Sandy
at 2013-06-26T18:07
at 2013-06-26T18:07
補習班選擇
By William
at 2013-06-26T17:50
at 2013-06-26T17:50
有沒有適合女生好考的鐵飯碗??
By Ingrid
at 2013-06-26T16:46
at 2013-06-26T16:46
數理統計
By Kristin
at 2013-06-26T16:33
at 2013-06-26T16:33