
6

简单指针实现两个数比较大小
source link: https://blog.51cto.com/u_15838996/5983882
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

简单指针实现两个数比较大小
精选 原创我们要先知道指针变量的作用是储存你指定变量所在的地址。因为按照计算机规则你所定义的值会被电脑储存在一个位置,只要是位置就会有地址。
#include<stdio.h>
int main()
{
int i,r;
int *p,*t;
printf("请输入两个值");
scanf("%d %d",&i,&r);
p=&i;t=&r;
if(r>i)
{
p=&r;
t=&i;
}//这里的作用就是交换两个指针变量所储存的地址以达到交换作用
printf("i=%d,r=%d,max=%d,min=%d",i,r,*p,*t); //这里的*号就相当于通过这个地址找到了这个数据。
return 0;
}
int main()
{
int i,r;
int *p,*t;
printf("请输入两个值");
scanf("%d %d",&i,&r);
p=&i;t=&r;
if(r>i)
{
p=&r;
t=&i;
}//这里的作用就是交换两个指针变量所储存的地址以达到交换作用
printf("i=%d,r=%d,max=%d,min=%d",i,r,*p,*t); //这里的*号就相当于通过这个地址找到了这个数据。
return 0;
}

- 赞
- 收藏
- 评论
- 分享
- 举报
</div
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK