I've found this code on web as an example, but I think this is not correct. An address to automatic variable is returned and this is just coincidence that it might work sometimes:
returning a pointer to an destroyed local variable, which becomes invalid memory location, is undefined behavior.
My only little hesitancy is about the pointer being static, but I think this changes nothing as this is the variable that should be static not a pointer: local variable is going to be destroyed. Can you please confirm or deny?
double *& showNumber()
{
double n = 1550.85;
static double *v = &n;
return v;
}
int main(int argc, char *argv[])
{
double sn = *showNumber();
sn = *showNumber();
//...
}