I always thought that new would allocate the memory until you called delete [] pointer; but when the function exits, does the function implicitly call delete[] or does new have a scope I didn't know about?
Those variables have the same name, but they are not on the same address. You have 2 places in memory which you can access by using the name "pointer" in your code. One is only valid within test and you write into it the address of some block of memory you allocated. As soon as the function is left that memory is still allocated but the place in memory where you wrote it's address down is no longer accessible.
What you want is either a pointer to a pointer or a reference to a pointer.