改错题 下列给定程序中,函数fun的功能是:通过某种方式实现两个变量值的交换,规定下允许增加语句和表达式。例如变量a中的值原为8,b中的值原为3,程序运行后a中的值为3,b的值为8。
请改正程序中的错误,使其能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题 程序:
#include <conio.h>
#include <stdio.h>
int fun(int *x, int y)
{
int t;
/********found********/
t = x; x = y;
/********found********/
return (y);
}
main()
{
int a = 3, b = 8;
printf("%d %d\n", a, b);
b = fun(&a, b);
printf("%d %d\n", a, b);
}
第1处:t=x;x=y;应改为t=*x;*x=y;
第2处:return(y);应改为return(t);或return t;