#include <stdio.h>
typedef void (*VPF) (int *, int *);
void Square(int *rX, int *rY);
void Swap(int *rX, int *rY);
void PrintVals(VPF,int , int );
int main()
{
int valOne=2, valTwo=5;
VPF pFunc;
pFunc = Swap;
PrintVals ( pFunc, valOne, valTwo);
pFunc = Square;
PrintVals ( pFunc, valOne, valTwo);
return 0;
}
void PrintVals( VPF pFunc,int x, int y)
{
printf("x:%d y:%d\n",x,y);
pFunc(&x,&y);
printf("x:%d y:%d\n",x,y);
printf("\n");
}
void Square(int *rX, int *rY)
{
(*rX) *= (*rX);
(*rY) *= (*rY);
}
void Swap(int *rX, int *rY)
{
int temp;
temp = *rX;
*rX = *rY;
*rY = temp;
}
執行結果:
x:2 y:5
x:5 y:2
x:2 y:5
x:4 y:25
沒有留言:
張貼留言