I'm trying to create function that returns an array but when using
int x[5];
void setup() {
x = getX();
}
int * getX(){
return {1,1,1,1,1};
}
I get: incompatible types in assignment of 'int*' to 'int [5]'
Your Arduino-IDE may not support C++'s std::array like mentioned in a comment, but you can do it like:
int* get() {
static int my_array[] = {1, 1, 1, 1, 1};
return my_array;
}
It's no possible to reasign an array like you've tried in your setup function.
Consider using:
int* x = nullptr;
void setup() {
x = get();
}
I've to point out, that this is not best practice. Maybe you can give some more information to find a better solution.
std::array. InCthere is no such feature like assignment between arrays so you have to use C++ specific feature.