关于指针问题
float* f(const float& a, const float& b){
float result = (a + b) * 0.5f;
return &result;
};
int main(int argc, char* argv[])
{
float a = 10, b = 20;
float *result2 = f(a,b);
float result1 = *f(a,b);
printf("result2: %f, result1: %f\n", *result2, result1);
printf("result2: %f, result1: %f\n", *result2, result1);
return 0;
}
为何两个printf结果不一样?