#include
void exe(int** p, int** q);
void main()
{
int *p, *q, a, b;
scanf("%d %d", &a, &b);
p = &a;
q = &b;
if (a < b)
{
exe(&p, &q);
}
printf("a=%d,b=%d\n", a, b);
printf("max=%d,min=%d\n", *p, *q);
}
void exe(int** p, int** q)
{
int* t;
t = *p;
*p = *q;
*q = t;
}
#include
void exe(int *p,int *q);
main()
{
int *p,*q,a,b;
scanf("%d %d",&a,&b);
printf("a=%d,b=%d\n",a,b);
p = &a;
q = &b;
if(a
{
exe(p,q);
}
printf("max=%d,min=%d\n",*p,*q);
}
void exe(int*p,int*q)
{
int t;
t=*p;
*p=*q;
*q=t;
}
在函数exe中,应该用指针来改变它指向的值,而不单纯改变指针的值。因为这个指针只是一个拷贝,改变它的值毫无意义
void exe(int *p, int *q);
int main()
{
int *p, *q, a, b;
scanf("%d%d", &a, &b);
p = &a;
q = &b;
if (a < b)
{
printf("a=%d,b=%d\n", a, b);
exe(p, q);
printf("max=%d,min=%d\n", *p, *q);
}
return 0;
}
void exe(int* p, int* q)
{
int t;
t = *p;
*p = *q;
*q = t;
}