101 關務四等計算機概要 - 考試
By Zenobia
at 2013-06-11T22:10
at 2013-06-11T22:10
Table of Contents
這樣改就可以交換嚕! 給原po做參考^ ^
c version:
swap.c
: #include <stdio.h>
void swap (int *a, int *b) { //位址所指的內含值
int t = *a;
*a = *b;
*b = t;
: }
: main() {
: int x =1, y=2;
swap(&x, &y); //把位址丟給函數
: printf("%d, %d\n", x, y);
: }
c++
swap.cpp
#include <iostream>
using namespace std;
void swap(int &x , int &y)
{
int t;
t = x ;
x = y;
y = t;
}
int main(void)
{
int a = 1;
int b = 2;
swap (a, b);
cout << "a="<< a << endl;
cout << "b="<< b << endl;
return 0;
}
※ 引述《pinky94 (pinky)》之銘言:
: [考題] 國考歷屆考題與考題觀念討論(書裡看到的選這個)請附上想法、出處
: 出處:如題
: 下列C語言程式,產生的輸出為何?
: #include <stdio.h>
: void swap (int a, int b) {
: int t = a;
: a = b;
: b = t;
: }
: main() {
: int x =1, y=2;
: swap(x, y);
: printf("%d, %d\n", x, y);
: }
: 猨
: (A)1, 2
: 獏
: (B)2, 1
: 獱
: (C)1, 1
: 斅
: (D)2, 2
: 答案:#
: 請問執行後應該不會變xy的值,所以不是應是A嗎?
--
Tags:
考試
All Comments
By Bethany
at 2013-06-16T01:23
at 2013-06-16T01:23
Related Posts
公海殺人算犯國內刑法殺人罪?
By Ula
at 2013-06-11T22:05
at 2013-06-11T22:05
企管問題
By Kama
at 2013-06-11T21:58
at 2013-06-11T21:58
中華電信考試疑問
By Connor
at 2013-06-11T21:49
at 2013-06-11T21:49
用Windows Media Player聽函授
By Caitlin
at 2013-06-11T21:30
at 2013-06-11T21:30
刑法不作為犯
By Delia
at 2013-06-11T21:26
at 2013-06-11T21:26