FSTRUCT() pointers can be used as return value in none UFUNCTION() function, but not as a parameter return value

I made this observation when some of my functions could return a FStruct pointer but some couldn’t (they where always Null).
I have a TArray with FStructs that i wanted to get references from. To do that i made a function that creates a pointer to the struct i want, like this:

void function(FStruct* structPointer)
{
  structPointer = &MyArray[0];
}

But this pointer is always Null outside the function.
But if you do it like this it works:

FStruct* function()
{
  return &MyArray[0];
}

Why does it work like this? And is it safe to use my solution to get a pointer to a struct?
In UFUNCTIONs you can’t even use FStruct pointers.

Thats because you just setting local argument variable which will get deleted when function is over. Pointers work like integers, which contain memory address to variable and you can access content of it with * and → operators, ince it works like integer, when you do = you will simply change address of pointer in that argument value, but it still gonna be deleted same as you would use int32.

So you either need to use reference:

 void function(FStruct*& structPointer)
 {
   structPointer = &MyArray[0];
 }

Refrence works like pointer but it with constsant address and it behaves like normal varbale

http://en.cppreference.com/w/cpp/language/reference

or modify value that pointer pointing to direcly:

 void function(FStruct* structPointer)
 {
   *structPointer = MyArray[0];
 }

I forgot to mention something important, you should not create pointers from array values, because array can do memory reallocation when new item is added to it, which may cause change of memory address of array items and pointer you used array item will become invalid and wither give trash values or crash the game. so 2nd option i gaved you is most safe one

Thank you for the answer. Luckily im never going to change the array after initialization so this will work.