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. How can I make it possible, thanks a lot!
Two things, if maxVal
is double, you cannot assign value of &max
. It should be double *
.
Secondly, never return address of local variable. Because once you return from function, local variable die.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.