C语言

tech2024-08-09  47

/* 题目:用指针指向两个变量,通过指针运算选出值最小的那个数 */ # include <stdio.h> int main(void) { int a, b, min, *pa, *pb, *pmin; pa = &a; pb = &b; pmin = &min; scanf("%d%d", pa, pb); //pa,pb已经是地址,所以前面不用加& printf("a=%d b=%d\n", a, b); *pmin = *pa; //a赋值给*pmin,即min if (*pa > *pb) //如果a > b *pmin = *pb; //那么将b赋值给*pmin,即min printf("min = %d\n", min); return 0; } /*结果: 10 20 a=10 b=20 min = 10 请按任意键继续. . . */
最新回复(0)