84、指针的应用场景
①在被调函数中可以修改主调函数变量的值。(参考练习28)
②让函数有多个返回值。(并不是有多个return)
eg:调用函数实现加减乘除算法。
void SuanFa(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 a = 3;
int b = 4;
int jia = 0;
int jian = 0;
int cheng = 1;
float chu = 1.00f;
SuanFa(a,b,&jia,&jian,&cheng,&chu);
printf("a,b加减乘除的结果分别是%d %d %d %.2f",jia,jian,cheng,chu);
}
|
|