← 回題庫

卷別

資料結構

選擇

國立中央大學 2026 · 考試 · 第 36 題

Which of the following C functions/macros are valid codes to swap two int variables?

M1.

#define SWAP(type,a,b) {type temp=a;a=b;b=temp;}
//SWAP(int,a,b)

M2.

#define SWAP(a,b) (a+=b,b=a-b,a-=b)
//SWAP(a,b);

F3.

void swap(int* a, int* b) {
int temp;
temp = *a;
*a = *b;
*b = temp;
}
//int x,y; swap(&x,&y);

F4.

void swap(int* a, int* b) {
*a = *b;
*b = *a;
}
//int x,y; swap(&x,&y);

F5.

void swap(int a, int b) {
int temp;
temp = a;
a = b;
b = temp;
Return;
}
//int x,y; swap(x,y);
  • (A)
    M1 and M2 only
  • (B)
    F3 only
  • (C)
    M2 and F3
  • (D)
    M1, M2, and F3
  • (E)
    All

標準解析

AI 生成