通过指针变量访问整型变量。
程序:
#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;
}
结果:
a=2,b=3
*p1=2,*p2=3
请按任意键继续. . .
本文出自 “岩枭” 博客,请务必保留此出处http://yaoyaolx.blog.51cto.com/10732111/1751263
原文:http://yaoyaolx.blog.51cto.com/10732111/1751263