- /*
- 定义多个指针实现返回多个返回值。
- */
- #include <stdio.h>
- void jiSuan(int x,int y,int *jia,int *jian,int *cheng,float *chu){
- *jia = x+y;
- *jian = x-y;
- *cheng = x*y;
- *chu = x/(float)y;
- }
- int main(int argc, const char * argv[]) {
- int jia,jian,cheng;
- float chu;
-
- int *p = &jia;
- int *p1 = &jian;
- int *p2 = &cheng;
- float *p3 = &chu;
- jiSuan(9, 2, p, p1, p2, p3);
- printf("x+y = %d\nx-y = %d\nx*y = %d\nx/y = %.2f\n",jia,jian,cheng,chu);
- return 0;
- }
复制代码
运行结果:
- x+y = 11
- x-y = 7
- x*y = 18
- x/y = 4.50
- Program ended with exit code: 0
复制代码 |