# C++ - Using Pointers as parameters/return for arrays

**URL:** <https://forums.unrealengine.com/t/c-using-pointers-as-parameters-return-for-arrays/364739>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [July 21, 2016, 9:41pm UTC](https://forums.unrealengine.com/t/c-using-pointers-as-parameters-return-for-arrays/364739 "2016-07-21T21:41:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RAVaught](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RAVaught](https://forums.unrealengine.com/u/RAVaught)\
**Post date:** [July 21, 2016, 9:41pm UTC](https://forums.unrealengine.com/t/c-using-pointers-as-parameters-return-for-arrays/364739/1 "2016-07-21T21:41:24Z")

</div>

Ok, so I am trying to wrap my head around C++ by starting out with a simple function library that handles some tasks I know I will need repeatedly throughout my game code. This particular function is meant to fill in an array with values calculated for a clamped sine wave.

BPFLibray.h

```
	UFUNCTION(BlueprintCallable, Category = "Test")
	int WaveClampedSine(int* amplitude, int* frequency, int* phase);

```

BPFLibrary.cpp

```
int WaveClampedSine(int* amplitude, int* frequency, int* phase)
{
	int i;
	int data= (int*)malloc(S*sizeof(int));
	for (i = 0; i <= 99; ++i)
	{
		*data[i] = *amplitude * sin(*frequency * i + *phase);
	};
	return *data;
	
}

```

I’ve tried implementing this several different ways, and all of them give me the same error:

“Inappropriate ‘\*’ on variable of type ‘int’, cannot have an exposed pointer to this type.”

I find it rather difficult to believe that UE4 does not support pointers at all, but it doesn’t seem to matter which data type I try to use, I always get the same error. Am I missing something or doing something wrong here? (And yes, I realize there are probably far more mistakes in my code then I currently realize.)

---

<div class="post-metadata">

**Author:** ![fabianu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fabianu](https://forums.unrealengine.com/u/fabianu)\
**Post date:** [July 21, 2016, 10:18pm UTC](https://forums.unrealengine.com/t/c-using-pointers-as-parameters-return-for-arrays/364739/2 "2016-07-21T22:18:03Z")

</div>

Hi there.

The reason for your error is that unreal engine 4 does not support the int type. The type you are looking for is int32.  
For further information take a look at this question:

> **[Why am I Getting Unrecognized type 'int'?](https://forums.unrealengine.com/questions/45937/getting-unrecognized-type-int.html)**
>
> So i'm trying to create a basic Actor based class A Coin, you pick it up, you get X amount of points (as decided by a variable)... In BP this is a fairly simple thing, but in C++ It won't work like expected, UPROPERTY(EditAnywhere,...

The next thing is that you should not use pointers to pass the array but use the engines TArray type instead:

> **[TArray](https://docs.unrealengine.com/4.27/en-US/API/Runtime/Core/Containers/TArray/)**
>
> Templated dynamic array

And unreal engine has support for pointers as given here:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

But a better way than using this smart pointers would be to use the engines implementation of smart pointers as documented here:

> **[Unreal Smart Pointer Library](https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/SmartPointerLibrary/)**
>
> Custom implementation of shared pointers, including weak pointers and non-nullable shared references.

---

<div class="post-metadata">

**Author:** ![rantrod](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rantrod](https://forums.unrealengine.com/u/rantrod)\
**Post date:** [July 21, 2016, 11:02pm UTC](https://forums.unrealengine.com/t/c-using-pointers-as-parameters-return-for-arrays/364739/3 "2016-07-21T23:02:40Z")

</div>

UFUNCTIONs are meant to be used in Blueprints. There’s no node to get addresses of variables in blueprints. Only UObjects or classes derived from them are references as pointers on the C++ side. Every other data type is passed by reference, including structs.

Your function would be more UE4-esque like this:

```
UFUNCTION(BlueprintCallable, Category = "Test")
void WaveClampedSine(int amplitude, int frequency, int phase, int num, UPARAM(ref) TArray<int> &Results);

```

…

```
void UYourUObjectClass::WaveClampedSine(int amplitude, int frequency, int phase, int num, TArray<int> &Results)
{
	for (int i = 0; i <= num; ++i)
	{
		Results.Add(amplitude * FMath::Sin(frequency * i + phase));
	}
}

```
