
106年特種考試地方政府公務人員考試試題 代號:43460 全一張
(背面)
等別: 四等考試
類科: 資訊處理
科目: 程式設計概要
三、下列 C++程式執行後,試問 A、B、C值分別為多少?(25 分)
int F2(int &f, int f1) {
int sum = (f1 + f++);
return sum;
}
void F1(int &a, int b, int* c) {
for (int i = a, j = b; j >= 0; i++, j--) {
if (c[j] % 2 == 0)
c[j] = F2(a, b);
else
c[j] = F2(b, a);
}
}
void main() {
int A = 5, B = 3, C[4] = { 1,4,7,6 };
F1(A, B, C);
system("pause");
}
四、試問下列 C++程式碼逐一執行後,Value 與list 輸出結果各為多少?(25 分)
void swap_ref(int &a, int &b) {
int temp;
temp = a;
a = b;
b = temp;
}
void swap(int a, int b) {
int temp;
swap_ref(a, b);
temp = a;
a = b;
b = temp;
}
void main() {
int Value = 5, list[3] = { 1,2,3 };
swap(Value + list[2]++, ++list[0]);
swap_ref(list[0], ++list[2]);
}