引用指针变量比较两个整数的大小。
程序:
#include<stdio.h>
int main()
{
int *p1, *p2, *p, a, b;
printf("please enter two integer numbers:");
scanf("%d,%d", &a, &b);
p1 = &a;
p2 = &b;
if (a < b)
{
p = p1;
p1 = p2;
p2 = p;
/*p1=&b;
p2=&a;*/
}
printf("a=%d,b=%d\n", a, b);
printf("max=%d,min=%d\n", *p1, *p2);
return 0;
}
结果:
please enter two integer numbers:3,5
a=3,b=5
max=5,min=3
请按任意键继续. . .