代码
#include<stdio.h>
int max1(int num1,int num2)
{if(num1 < num2){num1 = num2;}else{num2 = num1;}
}
int max2(int *num1,int *num2)
{if(num1 < num2){*num1 = *num2; // 把 num2 赋值给 num1 }else{*num2 = *num1;}
}
int main()
{int num1 = 0,num2 = -2;int ret;max1(num1,num2);printf("num1 is %d\n",num1);printf("num2 is %d\n",num2);max2(&num1,&num2); //&num1 表示指向 num1 的指针,即变量 num1 的地址printf("num1 is %d\n",num1); printf("num2 is %d\n",num2);return 0;
}
结果