看下面的额程序:
```c
#include<stdio.h>
struct gas mpg1(struct gas che);
void mpg2(struct gas *aut);
struct gas
{
float distance;
float gals;
float mpg;
};
int main(void)
{
struct gas car={
100.0,
10.0,
10.0
};
printf("When the car goes %.3f KM and used %.3f oil, the mpg is %.3f .\n",car.distance,car.gals,car.mpg);
printf("***************\n");
mpg1(car);
printf("这里的数值没有发生变化:\n");
printf("When the car goes %.3f KM and used %.3f oil, the mpg is %.3f .\n",car.distance,car.gals,car.mpg);
car=mpg1(car);
printf("引用之后发生了变化:\n");
printf("When the car goes %.3f KM and used %.3f oil, the mpg is %.3f .\n",car.distance,car.gals,car.mpg);
printf("***************\n");
mpg2(&car);
printf("When the car goes %.3f KM and used %.3f oil, the mpg is %.3f .\n",car.distance,car.gals,car.mpg);
return 0;
}
struct gas mpg1(struct gas che)
{
che.distance=134;
che.gals=12;
che.mpg=11.17;
return che;
}
void mpg2(struct gas *aut)
{
aut->distance=98.8;
aut->gals=11.1;
aut->mpg=8.9;
}
运行结果:
问题: 为什么指针直接改变了 实参,而 直接用结构体 却不能改变 实参呢?