I know this won\'T work because the variable x gets destroyed when the function returns:
int* myFunction() { int x = 4; return &x; }
I would try something like this:
int myFunction2b( int * px ) { if( px ) { *px = 4; return 1; } // Choice 1: Assert or Report Error // Choice 2: Allocate memory for x. Caller has to be written accordingly. // My choice is 1 assert( 0 && "Argument is NULL pointer" ); return 0; }