[英]Error: a value of type “double*” cannot be assigned to an entity of type “double”
I encountered a problem while i type my code. 输入代码时遇到问题。
...
double* FindMax(const double* const arr, int n)
{
double max;
...
return &max;
}
int main()
{
...
maxVal = FindMax(value, numbers);
...
}
When I call the function FindMax, the program error and not allow me pass the value to function FindMax. 当我调用函数FindMax时,程序出错并且不允许我将值传递给函数FindMax。 How can I make it possible, thanks a lot!
我要如何使它成为可能,非常感谢!
Two things, if maxVal
is double, you cannot assign value of &max
. 两件事,如果
maxVal
为double,则无法分配&max
。 It should be double *
. 它应该是
double *
。
Secondly, never return address of local variable. 其次,永远不要返回局部变量的地址。 Because once you return from function, local variable die.
因为一旦从函数返回,局部变量就会死亡。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.