Pointers are addresses. If you pass a pointer into a function, the function can then modify data created outside the scope of the function. However, if you want to allocate memory inside a function for use outside the function, you need to pass in a double pointer. The reason is that pointers are passed by value, and the allocation assigns a new value to the pointer for the newly allocated block. But that new value is lost when the function returns. But you can use this method to do what you need:
void func(int * * pp)
{
* pp = new int;
}
use the func thus:
int * myPointer;
func(& myPointer);
// do stuff with myPointer
delete myPointer;