回复 7楼 TonyDeng
问题的关键不在这里、关键不是如何达到最终的目的,我最关心的问题其实是开始的swap函数为什么为出错、
因为本身这本来也没有什么现实意义
404 NOT FOUND
#include <stdio.h> void swap(int*, int*); int main(void) { int i; int j; int *pointer_max; int *pointer_min; scanf("%d",&i); scanf("%d",&j); pointer_max = &i; pointer_min = &j; if(i < j) swap(pointer_max, pointer_min); printf("max = %d , min = %d\n", *pointer_max,*pointer_min); return 0; } void swap(int* pointer_1, int* pointer_2) { int p; p = *pointer_1;//将pointer1指向的变量的值赋给p *pointer_1 = *pointer_2;//将pointer2指向的变量的值赋给pointer1指向的变量 *pointer_2 = p;//将p的值赋给pointer2指向的变量 }
#include <stdio.h> int main(void) { int i; int j; int *pointer_max; int *pointer_min; scanf("%d",&i); scanf("%d",&j); pointer_max = &i; pointer_min = &j; if(i < j) { int* p; p = pointer_max; printf("p=%p,pointer_max=%p\n",p,pointer_max); pointer_max = pointer_min; printf("pointer_max=%p,pointer_min=%p\n",pointer_max,pointer_min); pointer_min = p; printf("pointer_min=%p,p=%p\n",pointer_min,p); printf("pointer_max=%p,pointer_min=%p\n",pointer_max,pointer_min); } printf("pmax = %p , pmin = %p\n", pointer_max,pointer_min); printf("max=%d,min=%d",*pointer_max,*pointer_min); return 0; }