I know this won\'T work because the variable x gets destroyed when the function returns:
int* myFunction() { int x = 4; return &x; }
For C++, in many cases, just return by value. Even in cases of larger objects, RVO will frequently avoid unnecessary copying.