The function works because you are not actually accessing the memory that it being pointed at. You are simply assigning the destination pointer variable to point at the same memory address as the source pointer variable, nothing more. Since your 'num' variable does not actually point at a valid double value in memory, your code will have bad behavior if you try to dereference the pointer afterwards, since it is pointing at random memory. In other words:
int main()
{
double* num; // <- uninitialized, points at random memory
double* dest;
doubleAddr(num, &dest);
// 'dest' now points to the same address that 'num' points to
*dest = 12345.0; // BAD!!!!
return 0;
}
The correct way to make the code work is as follows:
int main()
{
double num; // <- physical value in memory
double* dest;
doubleAddr(&num, &dest);
// 'dest' now points at 'num'
*dest = 12345.0; // OK! 'num' is updated correctly
return 0;
}