return an array from a function

I want to return an array from a function. But I get the follow error : In function 'int getRGB()': error: invalid conversion from 'int*' to 'int' In function 'void loop()':

Writing : int getRGB()[3] doesn't seem to work : error: 'getRGB' declared as function returning an array In function 'int getRGB()':

I searched in the forum but couldn't find a syntax for it.

Code example :

int colorsRGB[3];
int colors_1[3];
int colors_2[3];

int getRGB()
{ colorsRGB[0]=255;
   return colorsRGB;


You're getting into a relatively tricky area, touching on pointers, memory management, etc. The easiest solution is probably to pass an array into the function and simply write the result to it (rather than trying to return the array). That is:

int colors1[3];

void getRGB(int colors[3])
  colors[0] = 255;
  colors[1] = 0;
  colors[2] = 0;

void loop()

Ok, this works. I thought you always had to return someting to put a value into an array.

Would you mind to explain me how this works ( just curious ) ? How gets the data into the colors1 array ? Does it have to do with the fact that an array is a kind of a pointer ?