# Returning an array

**URL:** <https://forum.arduino.cc/t/returning-an-array/529726>\
**Category:** Programming\
**Created:** [June 3, 2018, 9:22pm UTC](https://forum.arduino.cc/t/returning-an-array/529726 "2018-06-03T21:22:56Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [June 3, 2018, 10:12pm UTC](https://forum.arduino.cc/t/returning-an-array/529726/6 "2018-06-03T22:12:09Z")

</div>

As stated, use pointers. But, then the local variable being returned must be 'static'. Also, you need some way of knowing the array's size in the calling function:

```cpp
void setup() {
  Serial.begin (115200);
}

void loop() {
  int *returnedArray;
  returnedArray = Test();
  for (uint8_t i = 0; i < 3; i++) {
    Serial.println(returnedArray[i]);
  }
}

int *Test() {
  static int test[] = {1, 2, 3};
  return test;
}

```

---

_[View the full topic](https://forum.arduino.cc/t/returning-an-array/529726)._
