考虑下面的 C 程序。它打印什么?
# include
# define swapl (a, b) tmp = a; a = b; b = tmp
void swap2 ( int a, int b)
{
int tmp;
tmp = a; a = b; b = tmp;
}
void swap3 (int*a, int*b)
{
int tmp;
tmp = *a; *a = *b; *b = tmp;
}
int main ()
{
int num1 = 5, num2 = 4, tmp;
if (num1 < num2) {swap1 (num1, num2);}
if (num1 < num2) {swap2 (num1 + 1, num2);}
if (num1 >= num2) {swap3 (&num1, &num2);}
printf ("%d, %d", num1, num2);
}
/* Add code here. Remove these lines if not writing code */
(一) 5、5
(二) 5、4
(三) 4、5
(四) 4, 4答案: (C)
说明: “if (num1 > = num2) {swap3 (&num1, &num2);}”语句为真,所以会执行引用调用。
这个问题的测验